TechnologY

Reverse the string using Shift Operator

My world turned upside down…MS written next Thursday and just got to know about it…

I am totally paranoid…sm1 teach me everything…

#include <stdio.h>int main(void)
{
  unsigned int original = 0xABC;
  unsigned int result = 0;
  unsigned int mask = 0xF;    

  printf(“\n original = %X”, original);

  /* Insert first digit in result */
  result |= original&mask;    

  /* Get second digit */
  original >>= 4;             
  result <<= 4;               
  result |= original&mask;    

  /* Get third digit */
  original >>= 4;             
  result <<= 4;               
  result |= original&mask;    
  printf(“\t result = %X\n”, result);
  return 0;
}

original = ABC  result = CBA
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s