+ 4
Can u explain how does bitwise right and bitwise left shift shift work ?
A detailed example .
13 odpowiedzi
+ 4
A bit shift moves each digit in a number's binary representation left or right. The last bit in the direction of the shift is lost, and a 0 bit is inserted on the other end.
For example:
Left shift by one bit
0010 << 1 = 0100
Just move every bit to it's left by one place.
Right shift by one bit
1010>>1= 0101
Just move every bit to it's right by one place.
+ 4
It took me a while but I made you this
https://code.sololearn.com/W0812gHagDUw/?ref=app
+ 3
No. Don't take out those last bits 10 to the front.
00110000 is the correct one
+ 2
Sure
1<<2
1 is 0001 in binary
Shift it 2 bits to the left
0001 00
0100 is 4 in decimal so
1<<2 = 4
The same rules apply for the right
+ 2
If we have 1 in a 4-bit binary as 0001 then
0001<<3 = 1000
+ 2
See this code:
https://code.sololearn.com/crourLU571OE/?ref=app
+ 1
I'm afraid I confused you. Look at it like this, let's say we have the number 5, which in binary is 0101 and shift it 4 bits. By this we mean, we move these bits, so it would be like this:
5<<4
this is five
0101
This is five shifted 4 places to the left
0101 0000
you take the number, and you move it to the left or right
+ 1
Like if we have 10001100 so <<
Will be 00110010 or it will be 00110000 ?
I'm little bit confused over this . Will the end places be covered by 0 or the ones written in front ?
+ 1
Don't worry about how many places because thats just formating.
0001 is the same than 1 and 0000 0001
It just helps us visualize by bytes, or count digits more easily
0
So 10 is picked up and placed at the position of 00 . So if we have 1 <<<3 it will be 0010 .is it ?
0
Yes but it should show till eight places isn't it? But here it is only showing 7 . Else everything I understood . How the shifting takes place . Thank you so much .😊
0
Yes . Thanks a lot for the help . 😊