I have a variable (unsigned int) part_1
.
If I do this:
NSLog(@"%u %08x", part_1, part_1);
(print unsigned value, and hex value) it outputs:
2063597568 7b000000
(only first two will have values).
I want to convert this to
0000007b
So i've tried doing
unsigned int part_1b = part_1 >> 6
(and lots of variations)
But this outputs:
32243712 01ec0000
Where am i going wrong?
The bitwise shift operators move the bit values of a binary object. The left operand specifies the value to be shifted. The right operand specifies the number of positions that the bits in the value are to be shifted. The result is not an lvalue.
Bitshifting shifts the binary representation of each pixel to the left or to the right by a pre-defined number of positions. Shifting a binary number by one bit is equivalent to multiplying (when shifting to the left) or dividing (when shifting to the right) the number by 2.
The right-shift operator causes the bit pattern in shift-expression to be shifted to the right by the number of positions specified by additive-expression . For unsigned numbers, the bit positions that have been vacated by the shift operation are zero-filled.
You want to shift by 6*4 = 24 bits, not just 6 bits. Each '0' in the hex printf represents 4 bits.
unsigned int part_1b = part_1 >> 24;
^^
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