Explain the shift operators, C/C++ Programming

Assignment Help:

The Shift Operators

There are 2 shift operators : left shift ( <<) and right shift (>>). These are binary operators. The format is

                operand >> number or operand << number

 

The first operand is the value, which is to be shifted. The second is the number of bits by which it is shifted. The left shift operators shift 'number' bits to the left, while the right shift operators shift 'number' bits to the right. The leftmost and the rightmost bits are shifted out and are lost.

e.g.

char x, y = 0x80;

                y = y >> 3;

                x = y <<2;

                y <<= 1;

                x >>=2;

The char y( which is allocated a byte of space on a 16-bit machine) will have its bits shifted to the right three places. The value of y which was 0x80(1000 0000) is changed to 0xFo (1111 0000) , after y = y>>3.

 


Related Discussions:- Explain the shift operators

C Programming, Develop a function to calculate sum of n even integers start...

Develop a function to calculate sum of n even integers starting from a given even integer

If statement, who to write max if statements in a program

who to write max if statements in a program

Why php is sometimes called as embedded scripting language, Why PHP is some...

Why PHP is sometimes called as embedded scripting language? PHP is a high level language that is used to allow users to write and understand it in human readable form and also

How can one "reopen" std::cin & std::cout in binary mode?, A: It is impleme...

A: It is implementation dependent. Verify with your compiler's documentation. For instance, assume you wish to do binary I/O using std::cin & std::cout. Unluckily there is no st

Explain nested classes, Nested Classes Many a times, it becomes essenti...

Nested Classes Many a times, it becomes essential to have a class contain properties of two other classes. One way is to explain a class within another - that is a class with m

Can copy constructor admit an object of the same class , Can copy construct...

Can copy constructor admit an object of the same class as parameter, rather than reference of the object?

C program for diviser, C Program for DIVISER   void main() {  ...

C Program for DIVISER   void main() {           int result,number,min;           clrscr();           printf("ENTER THE NUMBER=");           flushall();

Decompression of files compressed with LZW, The files are meteorological ra...

The files are meteorological radar data whose decompression is badly needed for relative study. Please contact Kathy Lee (Email: ; Cell phone: 0086 15701799056) or Mr. Zhu (Email:

Program is to reverse the names stored in an array pointer, Program is to r...

Program is to reverse the names stored in an array pointer: Program is to reverse the 6 names stored in an array pointer as name[] void main()   {  clrscr();  char

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd