in reply to
first 5 bits and last 3 bits
This posting may win some sort of award for ambiguity. What do "first" and "last" mean? Are the "first" the most significant, and the "last" the least significant? If, as the OP added, "it's 8 bits", which 8 bits? The most/least significant? If you strip away leading 0's, as the OP did, is it the 8 bits whose most significant bit is a 1 (which, of course, may not yield 8 bits)? There are many reasonable suggestions here, just as there are many reasonable interpretations of what the heck the OP wants. It doesn't help that the OP offered several suggestions on what the result should be.