I understand that 1 byte will hold a number from 0-255. And that a 16-bit number is between 0-65535.
If I'm trying to represent a 16-bit number using two separate 8-bit registers...how do I do that? How does the math work?
Thanks!
2-byte signed Integer [the ~] noun – An automation integer data type that can be either positive or negative. The most significant bit is the sign bit, which is 1 for negative values and 0 for positive values. The storage size of the integer is 2 bytes. A 2-byte signed integer can have a range from -32,768 to 32,767.
16-bit signed numbersThe smallest signed 16-bit number is -32768 and the largest is 32767. For example, 1101,0000,0000,01002 or 0xD004 is -32768+16384+4096+4 or -12284.
To join a list of Bytes, call the Byte. join(list) method. If you try to join a list of Bytes on a string delimiter, Python will throw a TypeError , so make sure to call it on a Byte object b' '. join(...)
The first code point positions in Unicode use 16 bits to represent the most commonly used characters in a number of languages. This Basic Multilingual Plane allows for 65,536 characters.
The math works out as follows:
sixteenBitNumber = 256*upperByte + lowerByte;
with shifts and bitwise operations:
sixteenBitNumber = (upperByte<<8) | lowerByte;
In most CPUs, even some archaic 8-bit ones, this interpretation is done in hardware: you load bytes into parts of a 16-bit register or into separate 8-bit registers that can work as a 16-bit pair, and the hardware works with the data as if it were a single 16-bit number.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With