Results 1 to 3 of 3

Thread: I need to reverse the bits in a short integer

  1. #1
    Geek_Guest
    Guest

    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


  2. #2
    Junior Member
    Join Date
    Jul 2007
    Answers
    18

    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);


  3. #3
    Junior Member
    Join Date
    Aug 2008
    Answers
    1

    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


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
About us
Applying for a job can be a stressful and frustrating experience, especially for someone who has never done it before. Considering that you are competing for the position with a at least a dozen other applicants, it is imperative that you thoroughly prepare for the job interview, in order to stand a good chance of getting hired. That's where GeekInterview can help.
Interact