lh-
Member level 1
hi
i'm writing a program in c++ where i have registers. they are 8 bit each. however, i may have values bigger than 255, in which case i need to place the value in say 2 registers if it has 16 bits, 3 registers for 24 bits etc.
so i need to extract first 8 bits (which for me are msb) and second 8 bits (lsb).
getting lsb didn't require me much of thinking:
for msb, this is what i come up with:
it works but i'm here to ask if there's a better solution.
thanks
i'm writing a program in c++ where i have registers. they are 8 bit each. however, i may have values bigger than 255, in which case i need to place the value in say 2 registers if it has 16 bits, 3 registers for 24 bits etc.
so i need to extract first 8 bits (which for me are msb) and second 8 bits (lsb).
getting lsb didn't require me much of thinking:
Code:
register = value & 0x00FF
for msb, this is what i come up with:
Code:
register = (value & 0xFF00) >> 8;
it works but i'm here to ask if there's a better solution.
thanks