The Bitwise Shift Operator Group
left shift ( << )
right shift ( >> )
unsigned right shift ( >>> )



Navigation Aids -- This Page        Navigation Aids -- This Topic        Navigation Aids -- This Site








Review of Terms Related to This Topic





The Purpose for this Page

This page will show the basic rules for JavaScript bitwise shift operator group. In addition, type conversions are discussed where applicable. Some special situation cases are explained. And finally, some scripting examples are provided with comments.





The Basics of Bitwise Shift Operators





Special Situations





Some Script Examples

For simplicity, we use only one byte in our examples. But the bitwise shift operators work with four bytes (32 bits).


Expression Giving Comment
x = 4;
x << 2
16 left shift
00000100 shifted to the left two bits giving 00010000; same as:: 4 * 22
x = -5;
x << 2
-20 left shift
11111011 shifted to the left two bits giving 11101100
x = 16;
x >> 2
4 right shift with sign extended
00010000 shifted to the right two bits and left filled with sign bit giving 00000100
x = -9;
x >> 2
-3 right shift with sign extended
11110111 shifted to the right two bits and left filled with sign bit giving 11111101
x = 16;
x >>> 4
1 right shift with zero fill
00010000 shifted to the right four bits and left zero filled giving 00000001
x = -10;
x >>> 3
30 right shift with zero fill
11110110 shifted to the right three bits and left zero filled giving 00011110


Top            

Rx4AJAX        About Us | Topic Index | Contact Us | Privacy Policy | 2008 This Site Built By PPThompson