Consider the VI, what is Numeric Value Out?
a) Numeric Value Out = ((A+B)-C) << (A+B)
b) Numeric Value Out = (A+B) << ((A+B)-C)
c) Numeric Value Out = ((A+B)-C) >> (A+B)
d) Numeric Value Out = (A+B) >> ((A+B)-C)
For this exercise the output result is option B.
The logical shift operation shifts all bits including the sign bit of a signed integer.
Anyone can explain how it works please? Thanks in advance
Hi A_rid, check this out.
SercoSteveB thank you! But in the event that (A+B)-C is less than zero, the result would it be simbolically the same??
The same as what? If (A+B)-C is negative, then we just shift in the other direction. So it would turn into (A+B) >> C-(A+B).
Ok now it's clear! Thank you crossrulz and SercoSteveB!
Yep, symbolically the same, but as crossrulz points out we would shift in the other direction.
Answer: B. Nice one all.
The input terminals for this one seem around the wrong way to me, I expect it to be Top Terminal Value << Bottom Terminal Value. I have to remember to reverse what I think when I use this one. Ho hum just another thing to remember.
LabVIEW 2017 Help for the Logical Shift function.
LabVIEW 2017 Help for the Logical Shift function does not explain anything to me. It says:
the function shifts x left y bits (from least significant to most significant bit) and inserts zeros in the low-order bits
But what it really means I have no clue. Too bad that I have no Labview during the preparation, so I can only guess what will be the x << y result. Can anyone explain what happens with the bits in a real life example?
I will just assume you know what a bit is and that numbers are nothing but a collection of bits. So what we are doing here is moving the bits in a number. So let's just say I have an U8 with a value of 10. We can represent that value in hex (0x0A) or in binary (0b00001010). The binary view shows the bits nicely. So now lets shift the bits by 1. 10 << 1 = 20 (0x14, 0b00010100). Just for fun, let's do a shift of -1. 10 << -1 = 10 >> 1 = 5 (0x05, 0b00000101).
If you still don't understand this, then I highly recommend taking some digital electronics courses.
Thank you crossrulz for explanation. I understand now. It is just takes a lot of time for me to understand that 10100 is 20 in binarese language.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.