devxlogo

Right shift

Right shift

Question:
Can you tell me how to write a program that right-shifts an integer variable 4 bits? The program should print the integer in bits before and after the shift operation.

Answer:
That’s too easy. C and C++’s >> operator will shift a value any number of bits.

i >>= 4;
I’ll leave the printing part up to you, though.

devx-admin

Share the Post: