I am trying to represent 32768 using 2 bytes. For the high byte, do I use the same values as the low byte and it will interpret them differently or do I put the actual values? So would I put something like 32678 0 or 256 0? Or neither of those? Any help is appreciated.
The bits of a word are numbered from 0 through 15; bit 0 is the least significant bit. The byte containing bit 0 of the word is called the low byte; the byte containing bit 15 is called the high byte.
The low byte is the byte that holds the least significant part of an integer. If you think in terms of writing a bit pattern on paper, the low byte is the rightmost eight bits. A short holds a 16-bit pattern such as: 01001010 00001111. The low order byte is 00001111 .
The byte is a unit of digital information that most commonly consists of eight bits. Historically, the byte was the number of bits used to encode a single character of text in a computer and for this reason it is the smallest addressable unit of memory in many computer architectures.
A byte is eight bits, a word is 2 bytes (16 bits), a doubleword is 4 bytes (32 bits), and a quadword is 8 bytes (64 bits).
In hexadecimal, your number is 0x8000 which is 0x80 and 0x00.
To get the low byte from the input, use low=input & 0xff
and to get the high byte, use high=(input>>8) & 0xff
.
Get the input back from the low and high byes like so: input=low | (high<<8)
.
Make sure the integer types you use are big enough to store these numbers. On 16-bit systems, unsigned int
/short
or signed
/unsigned long
should be be large enough.
Bytes can only contain values from 0 to 255, inclusive. 32768 is 0x8000, so the high byte is 128 and the low byte is 0.
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