10-08-2019 05:06 AM
hi guys
this place is full of solutions and can count on for any problem.
I wanted to convert a number in to Boolean array but since lowest representation is a byte I am getting an array of 8 bits when I need array of 4 bits.
thanks and regards
Baig
10-08-2019 05:22 AM - edited 10-08-2019 05:31 AM
Well, you could use a nibble (Yep, that is the term for 1/2 of a byte). just split your 8 bit array into two four bit arrays
Of course, that EXPLODES the memory needed from 1 byte to a lot (1 for the U8, 8 for the array of Boolean, four for the I32 index and a couple more for the array sizes)
10-08-2019 06:22 AM
HEY Thanks a lot for your response and time. I really appreciate it.
I also needed to be caution about memory use and time of execution. what I did is used array subset to get a nibble or half byte since I needed only first 4 bytes and there is the same problem of memory consumption as you said.
If these are the only ways of doing it then I would like to know which would be preferred for real time use and min consumption of time and memory.
Thanks and Regards
baig
10-08-2019 06:25 AM - edited 10-08-2019 06:32 AM
@mabaig wrote:
HEY Thanks a lot for your response and time. I really appreciate it.
I also needed to be caution about memory use and time of execution. what I did is used array subset to get a nibble or half byte since I needed only first 4 bytes and there is the same problem of memory consumption as you said.
If these are the only ways of doing it then I would like to know which would be preferred for real time use and min consumption of
timeand memory.Thanks and Regards
baig
Use the byte!.... Seriously, it requires only 2x the physical memory absolutely needed for a sextet .... ya got a 64bit bus! so the extra time to move data over that bus is nonsense! you need to move "Data" it fits into one bus at one time. 4, 8, 16, 32, 64 bits doesn't really matter except for the zeroes
10-08-2019 06:48 AM
I am just curious: If we use fixed point number with length of 4 bits like this:
The Number To Boolean Array function mentions that boolean array can have 8, 16, 32, 64 elements if we use integer, but can have flexible size if we use fixed point, in this case 4.
So if each boolean is a byte, we have 8 bytes from fixed point and 4 from boolean array which is 12 bytes total. If we use integers, we use (as you said) 1 for u8, 8 for bools, 4 for the index and then some, so it would be 13 bytes +.
Or do fixed points represented as decimals incur additional cost?
Atis
10-08-2019 07:23 AM
@JÞB wrote:
Of course, that EXPLODES the memory needed from 1 byte to a lot (1 for the U8, 8 for the array of Boolean, four for the I32 index and a couple more for the array sizes)
Think you missed the <s> ?
But really, a boolean requires a byte? 😮
10-08-2019 07:42 AM - edited 10-08-2019 07:43 AM
@cbutcher wrote:
@JÞB wrote:
Of course, that EXPLODES the memory needed from 1 byte to a lot (1 for the U8, 8 for the array of Boolean, four for the I32 index and a couple more for the array sizes)
Think you missed the <s> ?
But really, a boolean requires a byte? 😮
Yep, unless you grab a 4.x and place it in a type cast. (Don't do that)
10-08-2019 07:48 AM - edited 10-08-2019 07:51 AM
Ok, so moving back a bunch of steps...
What do you need this boolean array for?
It seems like the sensible options are:
10-08-2019 08:23 AM
@JÞB wrote:
@cbutcher wrote:
@JÞB wrote:
Of course, that EXPLODES the memory needed from 1 byte to a lot (1 for the U8, 8 for the array of Boolean, four for the I32 index and a couple more for the array sizes)
Think you missed the <s> ?
But really, a boolean requires a byte? 😮
Yep, unless you grab a 4.x and place it in a type cast. (Don't do that)
I want to add here that LabVIEW is far from the only language that does this. Almost everything in computer registers are accessed at the byte level. So it is just faster to let a Boolean be represented by a full byte. 0 is a FALSE. Anything else is a 1.
But are we seriously worried about these few extra bytes of memory?
10-08-2019 09:59 PM
Hey all... Thanks for the response
Well I've checked the execution here and I guess it doesn't make any big difference and hence can use either of the way. Of course, it's better to use byte but I am forming 32 bit Boolean array from different numbers. That's why only needed 4 bits from some numbers.
Thanks and regards
Baig