I HAVE WRITE CODE FOR ROTATING THE BINARY BIT IN CIRCULAR SHIFT AS FOR 101–>110 MEANS 5 BECOME 6 AFTER THE RIGHT CIRCULAR SHIFT https://ide.codingblocks.com/s/205945
Plesed healp me i am getting wrong o/p for odd no in my code
say for eg, your compiler reserve 2 bytes to store int, then 5 will be actually
0000000000000101 in binary and when you run your code in this value, it becomes->
1000000000000010… this is not 6, but ideally this is the right circular shift. if you want right circular shift, your code is correct. but if you want 6, you need to modify code a bit that it should take care of extra 0’s at start as well.
thanks
but how to modifiy code for extra bits please tell me
you can do it in following ways:
you have x= 0000000000000101
step1: right shift x by 1, say a = 0000000000000010
step2:
count = 0
while(x){
count++;
x = x>>1;
}
count will be 3 for this example.
step3: take b =1 and left shift b by count-1
b = 0000000000000100
step4: return a|b
thanks