top of page
Search

Swap two words in a byte

  • Ben
  • Feb 26, 2018
  • 1 min read

#include <iostream>

using namespace std;

int main() { unsigned int data=0x1234; cout<<"data before swapping :"<<hex<<data<<endl; //Binary representation of data = 0001 0010 0011 0100 // data <<8 0xff00 // (data<<8) & 0xff00 = (0011 0100 0000 0000) & (1111 1111 0000 0000)

// data >>8 0x00ff // (data>>8) & 0x00ff = (0000 0000 0011 0100) & (0000 0000 1111 1111) data= ((data<<8)&0xff00)|((data>>8)&0x00ff); cout<<"data after swapping :" <<hex<<data<<endl; return 0; }

 
 
 

Recent Posts

See All
Fibonacci series

#include <iostream> using namespace std; int main() { // Getting the input of fibonacci series long int n; cout<<"Enter the size of...

 
 
 

Comments


bottom of page