HEX values?

Discussion in 'Programmer's Corner' started by BReeves, Apr 14, 2013.

  1. BReeves

    Thread Starter Member

    Nov 24, 2012
    412
    64
    I need turn a 6 digit hex number into an 8 digit hex number with the 6 digits the least significant digits of the 8 digit number.

    In otherwords lets say I have... A00BCD, I need to end up with FFA00BCD. The leading FF in the 8 digit number will always be FF and range from FF000000 to FFFFFFFF.

    I know there must be an easy way to do this in C but it is escaping me.

    Thanks
     
  2. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,394
    1,606
    You need not do anything more then OR your number with 0xFF000000.
     
  3. kubeek

    AAC Fanatic!

    Sep 20, 2005
    4,670
    804
    How about number|=0xff000000; ? Obviously number needs to be the right size integer to hold it.
    Edit: aww snap, too slow :D
     
    ErnieM likes this.
  4. BReeves

    Thread Starter Member

    Nov 24, 2012
    412
    64
    Thanks guys, that was quick.. Can't believe this escaped me.. Getting old is a bitch.
     
  5. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,394
    1,606
    GMTA kubeek <grin>

    You at least gave him the code and the size warning.
     
  6. kubeek

    AAC Fanatic!

    Sep 20, 2005
    4,670
    804
    Yeah, but the size warning was kinda pointless, because you don´t usually get 3byte numbers, so if you can fit 3B you will be able to fit 4B. But the singned-ness will matter.
     
Loading...