+ 4

Can u explain how does bitwise right and bitwise left shift shift work ?

A detailed example .

11th Nov 2018, 3:32 AM
Sukanya
Sukanya - avatar
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.
11th Nov 2018, 3:58 AM
Шащи Ранжан
Шащи Ранжан - avatar
+ 4
It took me a while but I made you this https://code.sololearn.com/W0812gHagDUw/?ref=app
11th Nov 2018, 4:37 AM
voidneo
+ 3
No. Don't take out those last bits 10 to the front. 00110000 is the correct one
11th Nov 2018, 4:15 AM
Шащи Ранжан
Шащи Ранжан - avatar
+ 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
11th Nov 2018, 3:49 AM
voidneo
+ 2
If we have 1 in a 4-bit binary as 0001 then 0001<<3 = 1000
11th Nov 2018, 3:59 AM
Шащи Ранжан
Шащи Ранжан - avatar
26th Mar 2022, 3:35 PM
Siavash Kardar Tehran
Siavash Kardar Tehran - avatar
+ 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
11th Nov 2018, 3:59 AM
voidneo
+ 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 ?
11th Nov 2018, 4:14 AM
Sukanya
Sukanya - avatar
+ 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
11th Nov 2018, 5:01 AM
voidneo
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 ?
11th Nov 2018, 3:51 AM
Sukanya
Sukanya - avatar
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 .😊
11th Nov 2018, 4:57 AM
Sukanya
Sukanya - avatar
0
Yes . Thanks a lot for the help . 😊
11th Nov 2018, 5:02 AM
Sukanya
Sukanya - avatar