I've two integer of one byte, so each integer can be in the range 0-255. Suppose
a = 247
b = 8
Now the binary representation of each is:
a = 11110111
b = 00001000
What I need are the following operations:
1) Concat those two binary sequence, so following the example, "a" concat "b" would result in:
concat = 1111011100001000 -> that is 63240
2) Consider only the first n most significative bits, suppose the first 10 bits, this would resoult in:
msb = 1111011100000000
3) Revert the bits order, this would result in:
reverse = 0001000011101111
For the question number 2 I know it's just a shift operation, for the 3 I've guessed to convert in hex, then swap and then convert to integer, but I guess also that there are more elegant way.
For the number 1, I've wrote this solution, but I'm looking for something more elegant and performant:
a = 247
b = 8
first = hex(a)[2:].zfill(2)
second = hex(b)[2:].zfill(2)
concat = int("0x"+first+second,0)
Thank you