English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

xABCD rotated by 4 is xBCDA

2006-10-08 11:25:15 · 4 answers · asked by NH6ST 1 in Computers & Internet Programming & Design

4 answers

one way would be to save the LSB then divide by 2, then if the saved bit is a 1, OR the above with 0x8, if 0 then AND with 0x7.
pseudocode example:
num = 0xb //in binary it would be 1011
loop:
save LSB which is 1
num = num /2 //this gives you 0101
if LSB = 1
num = num | 0x8 //this gives you 1101
else
num = num & 0x7
repeat loop x number of times //in your example, repeat 3 times

2006-10-09 02:32:27 · answer #1 · answered by justme 7 · 1 0

Hmmm... I guess you will have to make your own steps...

You might try making two copies of the number, then AND each copy with a mask to get rid of the unwanted portions...

xABCD AND F000 for one, xABCD AND 0FFF for the other...

then shift the first one right 12 to get A into the first spot (x000A), shift the second one left 4 to get an empty right side (xBCD0)...

then combine the two with OR (x000A OR xBCD0 = xBCDA)

Doh!! sorry.. forgot the "bit wise".. you only need to do one bit then! not a full character!

2006-10-08 11:35:18 · answer #2 · answered by ♥Tom♥ 6 · 0 1

Assuming that you are using 32 bit integers and you want to rotate left:

y = (x << b) + (x >> (32 - b))

where:
x = the original number
b = # of bits you want to rotate
y = the answer

2006-10-08 18:23:31 · answer #3 · answered by Bryan A 2 · 0 1

Have fun...{:-{}.

2006-10-08 11:31:09 · answer #4 · answered by Anonymous · 0 0

fedest.com, questions and answers