LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

convert number to 4 bit binary array

Hi mabaig,

 


but I am forming 32 bit Boolean array from different numbers. That's why only needed 4 bits from some numbers. 

Then why do you need boolean arrays at all?

All you need are I32 values and some AND and SHIFT operations…

 

(You would have got that answer much earlier if you would have told the purpose of this exercise from the beginning!)

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 11 of 19
(2,156 Views)

@mabaig wrote:

I am forming 32 bit Boolean array from different numbers. That's why only needed 4 bits from some numbers. 


You can use AND with 1, 2, 4 and 8 to get your needed bits, i bet it's easier. 🙂

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
Message 12 of 19
(2,128 Views)

i needed to manipulate 32 bits word from hex number so converting this hex number to 32 bit Boolean array. 

Can you please send a screenshot what you told ( I32 valuese with AND and SHIFT operations)

 

thanks and regards

baig

0 Kudos
Message 13 of 19
(2,106 Views)

Hi mabaig,

 

like this:

check.png

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 14 of 19
(2,098 Views)

for example:

"1B1222AC" is a hex number. This hex number is to be decoded into 32 bits and is to be manipulated [1B(last 8 bits) is a checksum 1(1st decimal) 2 (2nd decimal) 2 (3rd decimal) 2 (4th 1/100th %f,decimal) of a intiger(here its 122.2 d) to be displayed and AC is start of word indication] 

this 1222 are 4 bit each from the hex number and to change it i needed Boolean array of 4 bits for each digit. later after changing like and manipulating to indicate(suppose 118.2) , again I needed to convert this 32 bit boolean array to hex number  as 1B1182AC.

 

I did this operation but since i lack skills in labview I had to use number to string and then string in forloop to get array of each digit in string then again string to number and again index array to get each digit desperately and then again that digit will be a boolean of 8 bits but i need 4 bits then again array subset i used. I know this is kinda stupid  way of doing that stuff. And that's why I am here :D.

 

Thanks and Regards 

Baig

0 Kudos
Message 15 of 19
(2,092 Views)

Hi Baig,

 


@mabaig wrote:

"1B1222AC" is a hex number. This hex number is to be decoded into 32 bits and is to be manipulated [1B(last 8 bits) is a checksum 1(1st decimal) 2 (2nd decimal) 2 (3rd decimal) 2 (4th 1/100th %f,decimal) of a intiger(here its 122.2 d) to be displayed and AC is start of word indication] 

this 1222 are 4 bit each from the hex number and to change it i needed Boolean array of 4 bits for each digit. later after changing like and manipulating to indicate(suppose 118.2) , again I needed to convert this 32 bit boolean array to hex number  as 1B1182AC.


Like this:

check.png

It's all about bit masking and shifting…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 16 of 19
(2,078 Views)

thats cool. Thanks alot. 

can we do the same to merge normal display numbers? since its a hex its works fine but to merge integer 4 and integer 5 to give 45 in normal display(not hex)?

Thanks and Regards

0 Kudos
Message 17 of 19
(2,057 Views)

Hi Baig,

 


@mabaig wrote:

can we do the same to merge normal display numbers? since its a hex its works fine but to merge integer 4 and integer 5 to give 45 in normal display(not hex)?

Why do it this complicated? Why not use these options:

  • simple math: 45 = 4*10 + 5 (for decimal numbers)
  • simple math: 45h = 4*10h + 5 (for hexadecimal numbers)
  • string conversion: use FormatIntoString with both values as input and a format string of %d%d

 

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 18 of 19
(2,048 Views)

Hi GredW 

I have did the same with  format into string option but wanted to simply a little (because I have 32 hex words to do and not all are decimal indicators but string, boolean and combobox) ':). Yeah you are right I might be making simple things complicated (just becoz i need to manipulate at bit level).

Thanks alot. Ill try simple maths and will get to you . 🙂 

 

Thanks and Regards

Baig

0 Kudos
Message 19 of 19
(2,038 Views)