Have a byte number and looking to check if bits are set or unset?
byte & 1
will be either 1 (last bit is set) or 0byte & 2
will be either 2 or 0- …
byte & 64
will be either 64 or 0byte & 128
will be either 128 (first bit is set) or 0
Want to sum up a subset of the byte's bits to get a number (say last 3 bits)?
(byte & 4) + (byte & 2) + (byte & 1)
First five bits?
((byte & 128) / 8) + … + (byte & 16) / 8
- the 8 comes from it going to the 4th bit from the last
Want to sum up a subset of bits across multiple bytes? Multiply each bit by the index of the byte squared.
The best way to show this will be to expand the formula and display arrows from the variables (like d1...dn for each digit) in the formula and the digits in the hex/bin form displayed. Consider instead of the variables showing the actual digit values where the arrows existing between them in the formula and in the displayed hex/bin would make sure they cannot be mistook for another digit of the same value.
Display that with indices once and then with real values again for obviousness.
Base this on the current code for the SVG of bit summing of the BE numbers.
When we have multiple forms (bin, hex, dec), display conversions to hex/bin if decimal or to dec if not decimal. See below about accepting multiple kinds of inputs and repeating the UI for them.
Change from number
input to text input and display the content for the number as dec, hex
and bin - all of these forms which match. Prevent invalid inputs from being input (only 0-9
and A through F in both cases). Repeat the UI (draw programatically) for each matching form.
https://gist.github.com/nphyx/5c19ef4cdb9774d87e0d + https://github.com/TomasHubelbauer/sqlite-javascript/blob/master/patchDataView.js
https://en.wikipedia.org/wiki/Endianness#Middle-endian
Currently -1
is all ones which sums up to non-sense (all parts).
Stretch the column width for all columns based on the part width of the widest part.
This way reading the current byte and its bit will work even for negative numbers.
Either still accept the corresponding number or derive it form the bytes? This is for
display after the =
sign. Also might still need to accept information about BE/LE
in order to display the right exponents in the right order (unless derivable from the
DataView
?).