mirror of
https://github.com/BorysLevytskyi/BitwiseCmd.git
synced 2025-12-20 11:42:39 +01:00
Add space between bytes
This commit is contained in:
@@ -2,14 +2,7 @@ import React from 'react';
|
|||||||
|
|
||||||
export default class BinaryStringView extends React.Component {
|
export default class BinaryStringView extends React.Component {
|
||||||
render() {
|
render() {
|
||||||
const str = this.props.binaryString;
|
return <span>{this.getChildren()}</span>
|
||||||
const chars = str.split('');
|
|
||||||
const allowFlipBits = this.props.allowFlipBits || false;
|
|
||||||
const css = allowFlipBits ? ' flipable' : ''
|
|
||||||
const classNames = { '0': `zero${css}`, '1' : `one ${css}` };
|
|
||||||
const children = chars.map((c, i) => <span className={classNames[c]} key={i} onClick={e => this.onBitClick(i, e)}>{c}</span>);
|
|
||||||
|
|
||||||
return <span>{children}</span>
|
|
||||||
}
|
}
|
||||||
|
|
||||||
onBitClick(index, e) {
|
onBitClick(index, e) {
|
||||||
@@ -21,4 +14,33 @@ export default class BinaryStringView extends React.Component {
|
|||||||
this.props.onFlipBit(index);
|
this.props.onFlipBit(index);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getChildren() {
|
||||||
|
var bits = this.createBits(this.props.binaryString.split(''));
|
||||||
|
|
||||||
|
if(this.props.emphasizeBytes) {
|
||||||
|
return this.splitIntoBytes(bits);
|
||||||
|
}
|
||||||
|
|
||||||
|
return bits;
|
||||||
|
}
|
||||||
|
|
||||||
|
createBits(bitChars) {
|
||||||
|
const allowFlipBits = this.props.allowFlipBits || false;
|
||||||
|
const css = allowFlipBits ? ' flipable' : ''
|
||||||
|
const classNames = { '0': `zero${css}`, '1' : `one ${css}` };
|
||||||
|
|
||||||
|
return bitChars.map((c, i) => <span className={classNames[c]} key={i} onClick={e => this.onBitClick(i, e)}>{c}</span>);
|
||||||
|
}
|
||||||
|
|
||||||
|
splitIntoBytes(bits) {
|
||||||
|
const bytes = [];
|
||||||
|
|
||||||
|
var key = 0;
|
||||||
|
while(bits.length > 0) {
|
||||||
|
bytes.push(<span key={key++} className="byte">{bits.splice(0, 8)}</span>);
|
||||||
|
}
|
||||||
|
|
||||||
|
return bytes;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -23,13 +23,13 @@ export default class BitwiseOperationEpxressionView extends React.Component {
|
|||||||
|
|
||||||
if(expr instanceof expression.SingleOperandExpression) {
|
if(expr instanceof expression.SingleOperandExpression) {
|
||||||
const m = BitwiseExpressionViewModel.buildNot(expr, { emphasizeBytes: this.props.emphasizeBytes });
|
const m = BitwiseExpressionViewModel.buildNot(expr, { emphasizeBytes: this.props.emphasizeBytes });
|
||||||
return m.items.map((itm, i) => <ExpressionRow key={i} {...itm} maxNumberOfBits={m.maxNumberOfBits} />);
|
return m.items.map((itm, i) => <ExpressionRow key={i} {...itm} emphasizeBytes={this.props.emphasizeBytes} maxNumberOfBits={m.maxNumberOfBits} />);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(expr instanceof expression.MultipleOperandsExpression) {
|
if(expr instanceof expression.MultipleOperandsExpression) {
|
||||||
const m = BitwiseExpressionViewModel.buildMultiple(expr, { emphasizeBytes: this.props.emphasizeBytes });
|
const m = BitwiseExpressionViewModel.buildMultiple(expr, { emphasizeBytes: this.props.emphasizeBytes });
|
||||||
console.log('Render model', m);
|
console.log('Render model', m);
|
||||||
return m.items.map((itm, i) => <ExpressionRow key={i} {...itm} maxNumberOfBits={m.maxNumberOfBits} />);
|
return m.items.map((itm, i) => <ExpressionRow key={i} {...itm} emphasizeBytes={this.props.emphasizeBytes} maxNumberOfBits={m.maxNumberOfBits} />);
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
@@ -38,13 +38,13 @@ export default class BitwiseOperationEpxressionView extends React.Component {
|
|||||||
|
|
||||||
class ExpressionRow extends React.Component {
|
class ExpressionRow extends React.Component {
|
||||||
render() {
|
render() {
|
||||||
const { sign, label, bin, other, css, maxNumberOfBits } = this.props;
|
const { sign, label, bin, other, css, maxNumberOfBits, emphasizeBytes } = this.props;
|
||||||
|
|
||||||
return <tr className={css}>
|
return <tr className={css}>
|
||||||
<td className="sign">{sign}</td>
|
<td className="sign">{sign}</td>
|
||||||
<td className="label">{label}</td>
|
<td className="label">{label}</td>
|
||||||
<td className="bin">
|
<td className="bin">
|
||||||
<BinaryStringView binaryString={formatter.padLeft(bin, maxNumberOfBits, '0')} allowFlipBits={false}/>
|
<BinaryStringView emphasizeBytes={emphasizeBytes} binaryString={formatter.padLeft(bin, maxNumberOfBits, '0')} allowFlipBits={false}/>
|
||||||
</td>
|
</td>
|
||||||
<td className="other">{other}</td>
|
<td className="other">{other}</td>
|
||||||
</tr>;
|
</tr>;
|
||||||
|
|||||||
@@ -23,7 +23,9 @@ export default class DisplayResult extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
renderUnknown() {
|
renderUnknown() {
|
||||||
return <div className="error">Sorry, i don't know what <strong>{this.props.input}</strong> is :(</div>
|
return <div className="result">
|
||||||
|
<div className="error">¯\_(ツ)_/¯ Sorry, i don't know what <strong>{this.props.input}</strong> is</div>
|
||||||
|
</div>
|
||||||
}
|
}
|
||||||
|
|
||||||
findResultComponent(result) {
|
findResultComponent(result) {
|
||||||
|
|||||||
@@ -35,7 +35,6 @@ export default class HelpResultView extends React.Component {
|
|||||||
<li><code><<</code> — left shift</li>
|
<li><code><<</code> — left shift</li>
|
||||||
<li><code>>></code> — sign propagating right shift</li>
|
<li><code>>></code> — sign propagating right shift</li>
|
||||||
<li><code>>>></code> — zero-fill right shift</li>
|
<li><code>>>></code> — zero-fill right shift</li>
|
||||||
|
|
||||||
</ul>
|
</ul>
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ export default class ListOfNumersExpressionView extends React.Component {
|
|||||||
render() {
|
render() {
|
||||||
const expr = this.props.expression;
|
const expr = this.props.expression;
|
||||||
const maxBitsLegnth = BitwiseExpressionViewModel.getNumberOfBits(expr.maxBitsLegnth, this.props.emphasizeBytes);
|
const maxBitsLegnth = BitwiseExpressionViewModel.getNumberOfBits(expr.maxBitsLegnth, this.props.emphasizeBytes);
|
||||||
const numberRows = expr.numbers.map((n, i) => <OperandView key={i} operand={n} maxBitsLegnth={maxBitsLegnth} />);
|
const numberRows = expr.numbers.map((n, i) => <OperandView key={i} operand={n} maxBitsLegnth={maxBitsLegnth} emphasizeBytes={this.props.emphasizeBytes} />);
|
||||||
return <table className="expression">
|
return <table className="expression">
|
||||||
<tbody>
|
<tbody>
|
||||||
{numberRows}
|
{numberRows}
|
||||||
@@ -28,7 +28,7 @@ class OperandView extends React.Component {
|
|||||||
|
|
||||||
return <tr data-kind={op.kind}>
|
return <tr data-kind={op.kind}>
|
||||||
<td className="label">{op.input}</td>
|
<td className="label">{op.input}</td>
|
||||||
<td className="bin"><BinaryStringView binaryString={binaryString} allowFlipBits={true} onFlipBit={e => this.flipBit(e)} /></td>
|
<td className="bin"><BinaryStringView emphasizeBytes={this.props.emphasizeBytes} binaryString={binaryString} allowFlipBits={true} onFlipBit={e => this.flipBit(e)} /></td>
|
||||||
<td className="other">{op.other}</td>
|
<td className="other">{op.other}</td>
|
||||||
</tr>;
|
</tr>;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user