Little Endian to Big Endian for 32 bit

Discussion in 'C++' started by invincible, Jun 14, 2005.

  1. invincible

    invincible Guest

    Regarding 16bit signed integer ,
    its working out fine. Thanks a lot . But I have similiar problem with 32 bit
    signed integer. Kindly help me out

    I have used
    ((s32Val << 24) | (s32Val >> 24) | ((s32Val >> 8)& 65280)
    | ((s32Val << 8)& 16711680))

    But it is not working with 32 bit signed integer

    Thanks for help
    invincible, Jun 14, 2005
    #1
    1. Advertising

  2. invincible

    red floyd Guest

    invincible wrote:
    > Regarding 16bit signed integer ,
    > its working out fine. Thanks a lot . But I have similiar problem with 32 bit
    > signed integer. Kindly help me out
    >
    > I have used
    > ((s32Val << 24) | (s32Val >> 24) | ((s32Val >> 8)& 65280)
    > | ((s32Val << 8)& 16711680))
    >
    > But it is not working with 32 bit signed integer
    >

    The right shift by 24 (second expression) should be "anded" with 255.
    Since you say "s32Val", I'm assuming you're signed, so the right-shift
    by 24 gets sign-extended.

    Incidentally, I'd recommend using hex constants to make it more obvious
    what you're doing, instead of the decimal ones.

    i.e.: 65280 = 0xff00, 16711680 = 0xff0000, 255 = 0xff
    red floyd, Jun 14, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. hicham
    Replies:
    2
    Views:
    9,023
    dxcoder
    Jul 2, 2003
  2. Ernst Murnleitner

    float: IEEE, big endian, little endian

    Ernst Murnleitner, Jan 13, 2004, in forum: C++
    Replies:
    0
    Views:
    865
    Ernst Murnleitner
    Jan 13, 2004
  3. invincible

    Little Endian to Big Endian

    invincible, Jun 14, 2005, in forum: C++
    Replies:
    9
    Views:
    14,352
    Old Wolf
    Jun 14, 2005
  4. Replies:
    5
    Views:
    348
    Stephen Sprunk
    Aug 31, 2006
  5. aling
    Replies:
    8
    Views:
    952
    Pete Becker
    Oct 19, 2005
Loading...

Share This Page