c++ - Bitwise operator to get byte from 32 bits -
I'm interested in writing a function function call However, I can use bitwise operators limited in it. Only me One idea is as follows: Suppose that you have a four-byte value: Suppose you want to get a byte This value is equal to what you want, except the Now, get a byte to get it If you subtract this again, then you and voice ... you've got the value you want! I will leave the actual code as a practice for the reader. do not worry; This is not particularly difficult: -) getMyByteChunkFunction which accepts two parameters - a 32 For example, this integer is given: -
- For example, the bit integer and a byte offset (0, 1, 2, or 3), then removes bytes related to 32-bit integers. (3) (2) (1) (0) --- byte numbers int word = 10101010 00001001 11001010 00000101
getMeByteChunkFunction (word, 2) Returns
00001001 .
& gt; & Gt; ,
& lt; I am allowed to use a , and exactly one subtraction I know how to do this and using XOR, but I do not know how I use a subtraction here Any thoughts?
aaaaaaaa bbbbbbbb cccccccc dddddddd
BBBBBBBB out of this if you move right by two bytes If you do, you can
???????? Reciprocity Aaaaaaaa bbbbbbbb
???????? Reciprocity Aaaaaaa (because we are not sure if the change is signal-protected or not, because I do not know if your value is unsigned). No worries; We can get rid of these unknown values and
a bytes. To get rid of the top, let's make a change to another byte,
???????? Reciprocity Reciprocity Aaaaaaa
???????? Reciprocity Aaaaaaaa 00000000
???????? Reciprocity Aahaya bbbbbbbb - ???????? Reciprocity Aaaaaaa 00000000 --------------------------------------- 00000000 00000000 00000000 Bbbbbbbb < / Ex>
Comments
Post a Comment