I know that (10001010<<2) = 00101000
And that (10001010>>2) = 00100010
How to shift when I have only one bit like this
(1<<5) and (1>>5)
I know that (10001010<<2) = 00101000
And that (10001010>>2) = 00100010
How to shift when I have only one bit like this
(1<<5) and (1>>5)
The type of 1
in C is int
, which is always larger than 1 bit.
Note that right-shifting a signed quantity is implementation-defined, but I guess most would give 0 since there's just a single 1 present and it's gone after the first bit shift.
First, if you do ( 010101 << 1 ) then it will consider "010101" as a decimal number and not a binary. The notation "0bxxx" tells the compiler that your number is binary ( 0b010101 ). For a single bit (your question), 1 decimal = 1 binary so you can use 1. However ( 1 >> anything ) should give you 0 all the time as you seem to know.
If you want to shift left, then this condition will return TRUE :
if( 8 == (1 << 3))
because (0b0001 << 3) = 0b1000 = 8