01-15-2015 02:45 PM
sticyfinger wrote:
@ Nathand
I did that in the past but I totally forgot that a negated number is negative. Plus I forgot that the number I was looking at was 32bits. L long week.
Not sure what you mean by this. If you negate an unsigned value, the result is an unsigned value with all the bits inverted. There's no need for all the To I32 conversions in your code. If you're only doing logical operations, and not mathematical ones, then it doesn't matter whether you use signed or unsigned values, either way you get the same series of bits. (Actually, due to the way two's complement works, even if you're doing math you'll often still get the same series of bits regardless of whether the values are signed - they'll just display differently on screen.)
01-15-2015 02:53 PM
I'm not sure whos is more efficient but here is another way to do the same thing with either the boolean array, or a number.
Unofficial Forum Rules and Guidelines
Get going with G! - LabVIEW Wiki.
17 Part Blog on Automotive CAN bus. - Hooovahh - LabVIEW Overlord
01-15-2015 03:02 PM - edited 01-15-2015 03:08 PM
For completeness in documenting bitwise boolean operations.
If you want to toggle a bit (i.e. turn on if off, or turn off if on, not knowing what the original state is or what it will be come, just that you want to change it), than you XOR it with a number that has that bit set to 1. XORing a bit with 0 is "leave that bit alone". XORing a bit with 1 is "flip that bit".
Note: I edited my description to be a bit more clear.
01-15-2015 03:06 PM - edited 01-15-2015 03:07 PM
******************************************
Actually since you are starting with a U8 for the "command", I would continue using that and use a U8 constant and final indicator. It's not logical for me to be thinking about the extra 24 bits in a U32 or I32 when I'm only dealing with an 8-bit command value. I'd be worried that mixing and matching other integer datatypes through carelessness would give me results I wasn't expecting. Try to be consistent in representation, and when by accident you miss changing the type of an integer, you'd see where your problems might be by way of the coercion dot.
********************************************
@ Raven,
yeah that make perfect sense. Thanks.
01-15-2015 04:01 PM
@Hooovahh wrote:
I'm not sure whos is more efficient but here is another way to do the same thing with either the boolean array, or a number.
You can safely assume that boolean arrays NEVER can be faster than a single number. A boolean array is an array of U8 with one U8 per bit. A number is simply a register. Go figure how much CPU operations each of them requires to perform a boolean operation on the whole thing!
01-15-2015 05:45 PM
@billko wrote:
I'm much better at visualizing flipping bits, so I convert to an array of booleans, flip the appropriate bit and convert it back to a number. I know it's not efficient, but for me I'm a lot less error-prone if I do it that way. I must have some kind of mental block.
Binary radix helps in that situation.
01-15-2015 06:25 PM
@crossrulz wrote:
@billko wrote:
I'm much better at visualizing flipping bits, so I convert to an array of booleans, flip the appropriate bit and convert it back to a number. I know it's not efficient, but for me I'm a lot less error-prone if I do it that way. I must have some kind of mental block.
Binary radix helps in that situation.
I've actually done that where I could, but sometimes the numbers are outputs and not contants. I envy people who can do this stuff inside their heads. Maybe it's like learning multiplication tables. You just have to do it often enough where it just becomes automatic.
01-15-2015 06:31 PM
@billko wrote:
I've actually done that where I could, but sometimes the numbers are outputs and not contants. I envy people who can do this stuff inside their heads. Maybe it's like learning multiplication tables. You just have to do it often enough where it just becomes automatic.
Well off-topic, but have you taught yourself to count in binary on your fingers? I've found it helps: for example you can read a number on screen, do it on your fingers, and see quickly which bits are on and which are off. Of course you're limited to 10 bits, and using more than 5 is inconvenient, but it is nice to be able to count to 31 on one hand. You can of course do this in either direction, but I start with my thumb as 1, forefinger as 2, etc up to the pinkie as 16.
01-15-2015 06:33 PM
@billko wrote:
@crossrulz wrote:
Binary radix helps in that situation.
I've actually done that where I could, but sometimes the numbers are outputs and not contants.
It works for controls and indicators as well.
Personally, I use the Hex radix a lot. It's just a little easier to read than a big string of 0s and 1s.
01-15-2015 06:35 PM
@crossrulz wrote:
@billko wrote:
@crossrulz wrote:
Binary radix helps in that situation.
I've actually done that where I could, but sometimes the numbers are outputs and not contants.
It works for controls and indicators as well.
Personally, I use the Hex radix a lot. It's just a little easier to read than a big string of 0s and 1s.
Sorry I've forced you to wander off-topic about this. I understand about controls and indicators, I meant outputs from calculations. I appreciate everyone's help and I'm sorry - I didn't mean to hijack the thread. 😞