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.

devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist