开发者

How do you convert little Endian to big Endian with bitwise operations?

I get that you'd want to do something like take the first four bits put them on a stack (reading from left to right) then do you just put them in a register and shift them x times to put them at the right part of the number?

Something like

1000 0000 | 0000 0000 | 0000 0000 | 0000 1011

Stack: bottom - 1101 - top shift it 28 times to the left

Then do something similar with the last four bits but shift to开发者_StackOverflow the right and store in a register.

Then you and that with an empty return value of 0

Is there an easier way?


Yes there is. Check out the _byteswap functions/intrinsics, and/or the bswap instruction.


You could do this way.. For example I/p : 0010 1000 and i want output 1000 0010

input store into a variable x int x; i = x>>4 j = x<<4 k = i | j print(K) //it will have 1000 0010.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜