I can't understand this topic in any of the lecture video but only this works thanks a lot for this simple nice and wonderful video I respect your teaching
There is no difference. There is however a difference for right shift. A logical right shift just shifts the bits along and fills the gap left at the left hand end with a zero - it is moving the place of the bits. An arithmetic right shift copies the most significant bit. This is useful when using two's complement numbers: -8 4 2 1 1 1 0 0 - this is two's complement for -4 0 1 1 0 - logical right shift has become positive 6- although it has moved the bit order 1 1 1 0 - arithmetic right shift - the gap is filled with the old most significant bit. -4 right shifted has become -2
Thank you for your answer been looking for this for half an hour and no ..... one does signed shifting! including you but at least in comments you did it. and another question if we do signed shift of positive number 0110 for example we will again copy msb which is 0 right? i havent came across any positive signed shifting made me question does signed mean negative or something...
msb will be copied anyway when using arithmetic right shift: either it is 1 or 0. The empty position in the most significant bit is filled with a copy of the original MSB.
Binary shifts are used to quickly multiply / divide by powers of two. They can also be used to zero out lower or upper bits (although bitwise and would probably be better), they can also be used in binary multiplication. I am sure there are other uses. I am not sure I understand your second question.
I am not quite sure what you mean. b10 as a binary number left shifted twice will be b1000 - or from 2 denary to 8 denary (and indeed from x2 to x8). If you mean x10 left shifted then x10 = b10000 and so left shifted is b01000000 which is x40 or denary 64. Lastly, if you are shifting places in hex then x10 would be x1000 which is whatever 16x16x16 is in denary.
If you use five or more bits to represent the number then you will get 20. In this case we were using just four bits which can represent the numbers 0-15 only - hence 20 won't fit in. If you left shift and have not got enough bits to represent the number then a computer processor will usually set an overflow flag. How to check for overflow varies between languages and architectures. The number of bits use to represent basic types like integers will vary too.
8 4 2 1 0 0 11 --> 3 --LS 1bit --> *2. This part is ok But if the register is has a fixed memory of 4 bit then the output should not go beyond 16, or you have an overflow, so for the above example it is necessary to restrict the operation to 2 left shifts only. Am i right? example: 8 4 2 1 1 0 1 1 -->LS, 1 bit != *2.
It isn't necessary to restrict it to 2 left shifts, but you will lose data. Consider a 32 bit IP address 192.168.1.45. if I do ip > 24 then I get left with 45. If I want to check if the most significant bit of a number is a 1 then I could do if ((number1==number) {}. This isn't the most effective way to do it, but it does work.
I've got a computer science examination tomorrow and I found your video extremely helpful thank you
Teach better than my teacher! And it's such a simple thing
Got a computing exam coming up, This really helped, thanks mate.
I can't understand this topic in any of the lecture video but only this works thanks a lot for this simple nice and wonderful video
I respect your teaching
Helped me clear so many doubts , Thanks Mr Powell's Computer Science Channel
Thank you so much!! This is so simple haha
whats the difference between a logical left shift and a arithmetic left shift?
There is no difference. There is however a difference for right shift. A logical right shift just shifts the bits along and fills the gap left at the left hand end with a zero - it is moving the place of the bits. An arithmetic right shift copies the most significant bit. This is useful when using two's complement numbers:
-8 4 2 1
1 1 0 0 - this is two's complement for -4
0 1 1 0 - logical right shift has become positive 6- although it has moved the bit order
1 1 1 0 - arithmetic right shift - the gap is filled with the old most significant bit. -4 right shifted has become -2
Thank you so much for explaining this simply. My professor doesn't teach us anything and the textbook is too in-depth.
Thank you for your answer been looking for this for half an hour and no ..... one does signed shifting! including you but at least in comments you did it. and another question if we do signed shift of positive number 0110 for example we will again copy msb which is 0 right? i havent came across any positive signed shifting made me question does signed mean negative or something...
msb will be copied anyway when using arithmetic right shift: either it is 1 or 0. The empty position in the most significant bit is filled with a copy of the original MSB.
Thank you very much.
Have you done a rotate binary video?
Thanks very helpful
Thanks for explaining. So may I know where we using these shifts and one more things how you make 5 or 10 after equal? Thanks
Binary shifts are used to quickly multiply / divide by powers of two. They can also be used to zero out lower or upper bits (although bitwise and would probably be better), they can also be used in binary multiplication. I am sure there are other uses. I am not sure I understand your second question.
so clear, very nice,
Thank you very much
What if you left shift the number 10 twice in hexadecimal(8 4 2 1)?
I am not quite sure what you mean. b10 as a binary number left shifted twice will be b1000 - or from 2 denary to 8 denary (and indeed from x2 to x8). If you mean x10 left shifted then x10 = b10000 and so left shifted is b01000000 which is x40 or denary 64. Lastly, if you are shifting places in hex then x10 would be x1000 which is whatever 16x16x16 is in denary.
Thank you!
64, 32, 16, 8, 4, 2, 1 for 7 bit
Thanks this was really useful !!!!
Thank you very much :)
Thank you so much for this
thanks Mr Powell!!!!!!
At 2:37 when I tried to shift again I got 4 shouldn't I get 20?
If you use five or more bits to represent the number then you will get 20. In this case we were using just four bits which can represent the numbers 0-15 only - hence 20 won't fit in.
If you left shift and have not got enough bits to represent the number then a computer processor will usually set an overflow flag. How to check for overflow varies between languages and architectures. The number of bits use to represent basic types like integers will vary too.
thanks very good video
fantastic .......thanks
3
Good
Easy to Understand
thanks man
helped a lot :)
nice. and easy to understand
well done m8 very good enjoyed your lesson
Thank you
Thats my teacher
thankssssssssssssssssssssssss
8 4 2 1 0 0 11 --> 3 --LS 1bit --> *2. This part is ok
But if the register is has a fixed memory of 4 bit then the output should not go beyond 16, or you have an overflow, so for the above example it is necessary to restrict the operation to 2 left shifts only. Am i right?
example: 8 4 2 1
1 0 1 1 -->LS, 1 bit != *2.
It isn't necessary to restrict it to 2 left shifts, but you will lose data. Consider a 32 bit IP address 192.168.1.45. if I do ip > 24 then I get left with 45. If I want to check if the most significant bit of a number is a 1 then I could do if ((number1==number) {}. This isn't the most effective way to do it, but it does work.
Safe bro
nice