Bitwise operators  Other operators

Chapter 1: Overview

Shift operators

Shift operators shift the bits in an expression to the left or to the right. The integer expression on the right of the operator determines how many places to the left or right to shift the bits within the expression on the left of the operator. When shifting left, all bits in the expression are shifted left one position and a zero is placed on the right. When shifting right, all bits in the expression are shifted right one position and a zero is placed on the left.

In the examples below, the bitwise value of “a” is 1010 0110 and “b” is equal to 2.

Table 1-7: Shift operators

Operator

Description

Example

<<

Left shift.

c = a << b;

The bitwise value of “c” is 1001 1000.

<<=

Left shift and assign.

a <<= b;

The new bitwise value of “a” is 1001 1000.

>>

Right shift.

c = a >> b;

The bitwise value of “c” is 0010 1001.

>>=

Right shift and assign.

a >>= b;

The new bitwise value of a is 0010 1001.





Copyright © 2005. Sybase Inc. All rights reserved. Other operators

View this book as PDF