Skip to content

Commit

Permalink
base-converter: Refresh automatically when num bits is changed
Browse files Browse the repository at this point in the history
  • Loading branch information
eliandoran committed Jul 12, 2024
1 parent 42e89d5 commit dde1f4c
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions src/routes/base-converter/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,18 @@
};
}
const twoComplement = {
to: (decimalValue) => {
return _twoComplement
.int2complement(decimalValue)
.toString(2)
.padStart(twoComplementBits, "0");
},
from: (sourceValue) => {
return _twoComplement.complement2int(sourceValue, twoComplementBits);
}
function twoComplement(numBits) {
return {
to: (decimalValue) => {
return _twoComplement
.int2complement(decimalValue)
.toString(2)
.padStart(numBits, "0");
},
from: (sourceValue) => {
return _twoComplement.complement2int(sourceValue, numBits);
}
};
};
const romanBase = {
Expand All @@ -55,7 +57,7 @@
<SingleBase fn={standardBaseConversion(16)} radixName="Hexadecimal" bind:decimalValue={decimalValue} />

<div class="two-complement">
<SingleBase fn={twoComplement} radixName="Two's complement" bind:decimalValue={decimalValue} />
<SingleBase fn={twoComplement(twoComplementBits)} radixName="Two's complement" bind:decimalValue={decimalValue} />
<InputField label="Number of bits">
<input type="number" min="1" step="1" bind:value={twoComplementBits} />
</InputField>
Expand Down

0 comments on commit dde1f4c

Please sign in to comment.