15th Apr 2020, 2:50 PM
Mustafa K.
Mustafa K. - avatar
12 Antworten
+ 3
It works on bitwise operator, Jusg check the post below you will understand it , otherwise there are lessons available on these on this app https://www.sololearn.com/discuss/186546/?ref=app https://www.sololearn.com/discuss/1422037/?ref=app https://www.sololearn.com/discuss/157184/?ref=app https://www.sololearn.com/discuss/1358560/?ref=app
15th Apr 2020, 2:54 PM
Raj Kalash Tiwari
Raj Kalash Tiwari - avatar
+ 3
Yes, you are right but it works on same principle let's suppose that the 8 bits are in circular form so it just shifts two value left or right as it does in other cases
15th Apr 2020, 2:59 PM
Raj Kalash Tiwari
Raj Kalash Tiwari - avatar
+ 3
Okkk, right shift, shifts values to right side by two and left shifts , shifts values to left side by two units , that. '1 ' s are shifted in both the cases
15th Apr 2020, 3:05 PM
Raj Kalash Tiwari
Raj Kalash Tiwari - avatar
+ 3
I>> 1 is I=11000000 That's fine But just I<<1 should be I=00000011
15th Apr 2020, 3:13 PM
Raj Kalash Tiwari
Raj Kalash Tiwari - avatar
+ 3
okkk , it is something exception for me too , sorry for all above
15th Apr 2020, 3:16 PM
Raj Kalash Tiwari
Raj Kalash Tiwari - avatar
+ 3
Raj Kalash Tiwari, in the C standard, left shift fills in vacated bits with 0. Right shift behavior depends on a couple factors. Right shift of an UNSIGNED quantity fills vacated bits with 0. Right shift of a SIGNED quantity is machine dependent. Some machines do an arithmetic shift (i.e. divide by 2) and retain the sign while others do a logical shift and fill in with 0. Aside: In machine language rotate instructions (not shift), at least some (if not all) machines use the carry bit to shift into or out of the word as filler. But empirically I have been unable to make C do that low level behavior.
15th Apr 2020, 9:10 PM
Brian
Brian - avatar
+ 2
As far as I'm aware....doing a right or left shift on a positive int introduces a '0' and bits are lost from the other end....but doing a right shift on a negative int introduces a '1' so as to preserve the sign bit.
15th Apr 2020, 5:44 PM
rodwynnejones
rodwynnejones - avatar
0
Raj Kalash Tiwari Did you take a look at my code before referring me to these?
15th Apr 2020, 2:57 PM
Mustafa K.
Mustafa K. - avatar
0
The thing what I did not understand is actually about the difference between right shift and left shift operator.
15th Apr 2020, 3:02 PM
Mustafa K.
Mustafa K. - avatar
0
What I say is, consider this example i = 1 0 0 0 0 0 0 1; i = i<<1; i = 0 0 0 0 0 0 1 0; But, i = i>>1; i = 1 1 0 0 0 0 0 0;
15th Apr 2020, 3:09 PM
Mustafa K.
Mustafa K. - avatar
0
Yea but it is not, that is what i was trying to point you out. When you run the code you'll see that, i << 1 is not 00000011 Instead it is, 00000010
15th Apr 2020, 3:15 PM
Mustafa K.
Mustafa K. - avatar
- 1
ei
17th Apr 2020, 7:20 PM
Emerson Sousa
Emerson Sousa - avatar