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

Program to list the cities and their states, The program will ask the user ...

The program will ask the user to enter: '1' to List the cities(and their state abbrev)  from largest to smallest (by their population) with their population '2'  to List the

Write function that take array as argument, Write a function that takes an ...

Write a function that takes an array as the argument and returns the second largest element. Bonus (+5): Write a function that takes an array and a number n as arguments and return

Define namespace in c++, It is a feature in C++ to reduce name collisions i...

It is a feature in C++ to reduce name collisions in the global name space. This namespace keyword assigns a separate name to a library that allows other libraries to use the simila

Why shouldn''t matrix class''s interface look like an array, Why shouldn't ...

Why shouldn't Matrix class's interface look like an array-of-array? A: Some people build a Matrix class that has an operator[] that returns a reference to an Array object (or po

Explain about the integer constants in c language, Explain about the Intege...

Explain about the Integer constants in c language? An integer constant is the integer valued number and it refers to a sequence of digits. A decimal integer constant includes o

Programming, Write a program that writes your name on the monitor ten times...

Write a program that writes your name on the monitor ten times. Write this program three times, once with each looping method.

Bitwise operations, Bitwise Operations 1. Write a function that has an ...

Bitwise Operations 1. Write a function that has an int parameter n, makes an integer mask having the bit 1 at the nth place from the rightmost bit, and returns the mask. For ex

Write a program to sort an array of strings, Write a program to sort an arr...

Write a program to sort an array of strings. Use new and delete operators. Write a program to find the factorial of a number using recursion. If we do not accept the number

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