Shift Operators

 <  Day Day Up  >  

The shift operators ( << and >> ) perform bitwise shifts on the binary representation of integer values. The << operator shifts the binary bits of a value left a specified number of places, while the >> operator shifts the binary bits of a value right a specified number of places (see Figure 5-2).

Figure 5-2. Left and Right Shifting

graphics/05fig02.gif

When a value is shifted left or right, bits that are shifted off the end of the value are discarded ”bit shifting will never cause an overflow. When bits are shifted left, the low-order bits are always filled with zeros. When bits are shifted right, the high-order bit is filled with the same value, 1 or , that it already contains. This preserves the sign of Short , Integer , and Long values when bits are shifted right (see Figure 5-3).

Figure 5-3. Right Shifting with Sign Preservation

graphics/05fig03.gif

It is possible to shift a value more places than the binary representation contains. In that case, the result will always be .

 <  Day Day Up  >  


The Visual Basic .NET Programming Language
The Visual Basic .NET Programming Language
ISBN: 0321169514
EAN: 2147483647
Year: 2004
Pages: 173
Authors: Paul Vick

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net