If I have a number 117, represented in binary as : 01110101 and I wanted to grab the top nibble. What would be the decimal value I would be extracting?
Would it be 0111 or 0101 decimal values 112 or 5 or is my understanding completely wrong?
Lets say I have three binary values 117,117,117 or
01110101 01110101 01110101 and I want to add the first byte to the top nibble of the second byte. Then I want to add the bottom nibble of the second byte to the third byte? Would it then be 117+7 and 5 + 117 ?
I'm reading a compressed stream in 8 bit characters. To decompress that stream it needs to take in 12 bits at a time. That 12 bits of information needs to come from the compressed stream. Therefore, for the first index I take the first byte + the top nibble of the second byte. For the second index I take the bottom nibble of the second byte and add it to the third byte.
It is the adding process I just wanted to confirm, hence my questions above.
Don't look into it too much. Just trying to confirm that I am using the correct logic for adding top and bottom nibbles to an existing 8 bit byte.
What file format are you reading? Sometimes people mess with bit order, which is weird and confusing (bit-endianness), but the first twelve bits in a file are bits 0-7 of the first byte and bits 0-3 of the second.
In this case, you aren't adding bits, you are concatenating them. (By using bit shifting and logical OR on the corresponding bits -- also called bitwise OR.)
Thanks for that. I'm using windows XP so from what I understand it uses Little Endian..
I just want to get my understanding right.. The two numbers 244,244 would display in memory as:
11110100 11110100 so if I am concatenating the first byte with the second byte (top nibble) eg.. 11110100 11110100 I would read the 12 bits as one variable in little endian format 111101001111 . Is that right? OR, should I always concatenate the first byte with the least significant bits of the second byte. eg..11110100 11110100 to equal 111101000100 ? Just wondering which one is correct?
I understand why you are so confused by all the different stuff you are reading.
There is byte endianness, which is an issue based on your hardware. But that is not the issue here (or shouldn't be -- you still haven't told me what file format you are trying to read -- it might be).
The issue is bit endianness. When reading the bits in a byte, usually bit 0 is the least significant. Sometimes, however, people consider it differently. So the bytes
244,123 == 0xF4, 0x7B == 1111 0100, 0111 1011
Should technically be bit-ordered 0010 1111 1101 1110, which is backwards from our usual view of numbers. Remember, in a stream, the least significant bits come first, whereas in a number the most-significant bit comes first.
So you read the first byte, and append the least-significant nibble of the second byte to the most-significant end of the first.