Geeks Talk

Prepare for your Next Interview




I need to reverse the bits in a short integer

This is a discussion on I need to reverse the bits in a short integer within the C and C++ forums, part of the Software Development category; I have short integer i need to reverse the bits in it ie first 8 bits in the second 8 bits position and second 8 bits in first 8 bit ...


Go Back   Geeks Talk > Software Development > C and C++

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 07-09-2007
Expert Member
 
Join Date: Feb 2007
Posts: 1,279
Thanks: 0
Thanked 164 Times in 138 Posts
Geek_Guest is on a distinguished roadGeek_Guest is on a distinguished road
I need to reverse the bits in a short integer

I have short integer i need to reverse the bits in it ie first 8 bits in the second 8 bits position and second 8 bits in first 8 bit position?

Question asked by visitor Philip
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 07-16-2007
Contributing Member
 
Join Date: Jul 2007
Location: India
Posts: 31
Thanks: 6
Thanked 4 Times in 4 Posts
kamanianil is on a distinguished road
Smile Re: I need to reverse the bits in a short integer

short int x,y; ( 16 bit )

y = x && 0X00ffh ;
x = x && 0X0ff00h ;

x = x << 8 ;
y = y << 8 ;

x = x || y;

Printf(" Exchange value is in x = %d",x);
Reply With Quote
  #3 (permalink)  
Old 10-02-2008
Junior Member
 
Join Date: Aug 2008
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
ofdrm is on a distinguished road
Smile Re: I need to reverse the bits in a short integer

How to reverse the bits in a short integer in Java

Code:
                int x = i & 0x00FF;
		int y = i & 0xFF00;
		
		x = x << 8;
		y = y >> 8;
		
		System.out.println("");
		System.out.println(x | y);
Logic remains same.... (there's some typo in the above post, I guess)...

-dibyaranjan
Reply With Quote
Reply

  Geeks Talk > Software Development > C and C++

« trees | help me »

Thread Tools
Display Modes


Similar Threads

Thread Thread Starter Forum Replies Last Post
How to learn basic XML in short time mounesh4k AJAX & XML 3 12-05-2007 03:02 PM
How do I reverse a string with sql query only? swanand11may SQL 4 07-09-2007 06:15 AM
values of bits from 4th to 12th position is my required final data shivaram.cunchala C and C++ 1 06-21-2007 11:44 PM
What is the next integer in this series? Manojks Brainteasers 5 01-18-2007 07:03 AM
Please give a Short and Crisp Answer janelyn Interviews 1 07-29-2006 04:12 PM


All times are GMT -4. The time now is 08:17 PM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Copyright © 2008 GeekInterview.com. All Rights Reserved