0

To assume tha I have number 54998 which in binar is:

54998=11010110 11010110

And now I have to break this number into 2 other numbers of the size of 8 bytes in binar,for example:

11010110=214 and 11010110=214

Any ideas to do it in C?

I thought about moving the number 8 bites to the right and finding the first number,but are there any other ways to do this?

number>>8;

1 Answers1

0

You are probably looking for bit masking:

void more_stuff(uint32_t value) {             // Example value: 0x010203
    uint32_t byte1 = (value >> 16);           // 0x010203 >> 16 is 0x01 so
                                              // no masking is necessary
    uint32_t byte2 = (value >> 8) & 0xff;     // 0x010203 >> 8 is 0x0102 so
                                              // we must mask to get 0x02
    uint32_t byte3 = value & 0xff;            // here we only mask, no shifting
                                              // is necessary
}
lxhom
  • 650
  • 4
  • 15