Search code examples
objective-chexnumbersdigits

Extract first two digits of hex (UInt32 *) and convert to int


I have a bunch of hex values stored as UInt32*

  • 2009-08-25 17:09:25.597 Particle[1211:20b] 68000000
  • 2009-08-25 17:09:25.598 Particle[1211:20b] A9000000
  • 2009-08-25 17:09:25.598 Particle[1211:20b] 99000000

When I convert to int as is, they're insane values when they should be from 0-255, I think. I think I just need to extract the first two digits. How do I do this? I tried dividing by 1000000 but I don't think that works in hex.


Solution

  • Objective C is essentially C with extra stuff on top. Your usual bit-shift operations (my_int >> 24 or whatever) should work.