How can we check any bit of a Number?

How can we check whether the n.th bit of an integer number is 1 or 0?
For example, is the 5th bit of 127 a 1 or a 0?
Can you help us how can we check this?


Here is how you can do it

4 Likes

Or like this:



blocks - 2023-04-30T114154.693
blocks - 2023-04-30T114158.786

In a byte, the first bit is bit0.

3 Likes

Thank you very much for your interest.

There is a bitwise AND block in the math section.
Calculate bitwise AND of 2^n , x to get the nth bit from the right.

nthBit_test

2 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.