How to read off 1 flag bit and get integer at same time
问题 Say I have an 8-bit number with a flag at either side: <flag>0101011 (decimal 43) 0101011<flag> (decimal 43) Not sure which is more optimal for what's next. Then say I want to check the flag, and then use the number. Wondering if that can be done in one operation. Or if not, the fewest operations it can be done in. 回答1: You could do something like this using the flag at the end: var num = 0b01010110; var flag = num & 1; var int = num >> 1; console.log(flag); console.log(int); But binary