Shift right : shift « Data Types « C++ Tutorial






#include <iostream> 
using namespace std; 
 
void show_binary(unsigned int u); 
 
int main() 
{ 
  int i=1, t; 
 
  
  for(t=0; t < 8; t++) { 
    i = i >> 1; 
    show_binary(i); 
  } 
 
  return 0; 
} 
// Display the bits within a byte. 
void show_binary(unsigned int u) 
{ 
  int t; 
 
  for(t=128; t>0; t=t/2) 
    if(u & t) cout << "1 "; 
    else cout << "0 "; 
 
  cout << "\n"; 
}
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0








2.14.shift
2.14.1.Shift left
2.14.2.Shift right
2.14.3.Left rotate functions for byte values
2.14.4.Right rotate functions for byte values
2.14.5.Demonstrate bitwise left shift
2.14.6.Demonstrate bitwise right shift