Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Home » Tip Bank » C++
Language: C++
Expertise: Beginner
Oct 29, 1998

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 Pro
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date