LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to convert decimal number to binary number

Hi everyone, I'll start by saying that I'm still new to Labview. I'm communicating with a lock in 5210 and I need to display a certain error in Labview. Let me explain better, I send the N command from Labview to the lock in which will return an integer between 0 and 255. This number is the decimal equivalent of a binary number. However, I don't know how to convert this integer and especially how to convert this "error" to display it on the panel. Because, for example, if bit 3 goes to 1 then I should turn on a LED to specify that channel Y is overloaded. I'm attaching the part of the lock in manual and the first part of the (incomplete) Labview code (there is also management of the ?, because if it were to return this character then the command must be resent, and * establishes the end of the number). I hope you can help me.

 

 

Download All
0 Kudos
Message 1 of 21
(242 Views)

Hi giuli,

 


@giuli_ wrote:

which will return an integer between 0 and 255. This number is the decimal equivalent of a binary number. However, I don't know how to convert this integer and especially how to convert this "error" to display it on the panel. Because, for example, if bit 3 goes to 1 then I should turn on a LED to specify that channel Y is overloaded.

Simplest approach (for people not used to boolean logic):

  • Use NumToBooleanArray to convert your U8 value into an array of 8 boolean elements.
  • Use IndexArray to index the required bits.

When you can apply boolean math rules to your data then you should use the AND function directly on your U8 integer value to mask bit3 (0d08 = 0x08 = 0o010 = 0b00001000)…

 

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 21
(236 Views)

Ok thank you. So after accumulating the characters (in the while) and after getting the string containing the decimal number, I convert it to a number and then to a boolean array? Right?

0 Kudos
Message 3 of 21
(222 Views)

Hi giuli,

 


@giuli_ wrote:

Ok thank you. So after accumulating the characters (in the while) and after getting the string containing the decimal number, I convert it to a number and then to a boolean array? Right?


Yes.

 

Do you really need to send and receive messages with your device on a "one byte after the other" scheme?

Have you watched this video yet?

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 4 of 21
(206 Views)

Thank you so much!!

0 Kudos
Message 5 of 21
(194 Views)

Maybe this is what you are looking for.

0 Kudos
Message 6 of 21
(129 Views)

You are getting a single byte, that has the equivalent decimal value in the range of 0..255. You don't get 1-3 decimal characters (bytes)!

 

altenbach_0-1750092468876.png

 

For that reason, you should typecast the single character to U8 and extract the bits

 

altenbach_1-1750092878584.png

 

0 Kudos
Message 7 of 21
(120 Views)

Here's a simple way to e.g. extract the active messages.

 

altenbach_0-1750093349043.png

 

Message 8 of 21
(114 Views)

Thank you!

0 Kudos
Message 9 of 21
(94 Views)

You can simplify the code using a cluster:

paul_a_cardinale_0-1750159279799.png

 

Message 10 of 21
(77 Views)