LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

how do i convert bytes to numbers?

hello. from a visa read, which is returning bits/bytes, i need to convert it to a number. the only conversion functions i see are "hexidecimal string to number" "and frac/exp string to number" etc. how do i convert if from bytes to decimal?
0 Kudos
Message 1 of 5
(3,155 Views)
NewMachine;

Under the Boolean palette there are two functions that can help you: "Boolean Array to Number" and "Boolean to (0,1)".

Regards;
Enrique
www.vartortech.com
Message 2 of 5
(3,153 Views)
It depends on what you are getting from the serial port. If you are getting a character string representation of a hex number, like FF 3A, then you can use the Hexidecimal String to Number function. If you are getting a wierd character, a smiley face or a square box, then you must use the Type Cast function found in Advanced - Data Manipulation palette on the block diagram. Wire serial string into Type Cast left side, wire a U32/U16/U8 constant into the top terminal of Type Cast. Converted number comes out of the right terminal. You must know whether the serial stream is a 32 bit or 16 bit or 8 bit number. If the serial string is FA 34 16 00, is this one number (FA341600), or is it two numbers (FA34 and 1600), or is it four numbers (FF and 34 and 16 and 00)? Use U8 if four numbers, U16 if two numbers, and U32 if one number.
- tbob

Inventor of the WORM Global
Message 3 of 5
(3,145 Views)
hello. the data is actually 8 bit - binary / 1 byte. would i still need to use the type cast if it is just in plain 'ol binary format.



@tbob wrote:
It depends on what you are getting from the serial port. If you are getting a character string representation of a hex number, like FF 3A, then you can use the Hexidecimal String to Number function. If you are getting a wierd character, a smiley face or a square box, then you must use the Type Cast function found in Advanced - Data Manipulation palette on the block diagram. Wire serial string into Type Cast left side, wire a U32/U16/U8 constant into the top terminal of Type Cast. Converted number comes out of the right terminal. You must know whether the serial stream is a 32 bit or 16 bit or 8 bit number. If the serial string is FA 34 16 00, is this one number (FA341600), or is it two numbers (FA34 and 1600), or is it four numbers (FF and 34 and 16 and 00)? Use U8 if four numbers, U16 if two numbers, and U32 if one number.


0 Kudos
Message 4 of 5
(3,119 Views)
If it is 8-bit binary, some of the characters should look like garbage characters (smiley faces, rectangles or squares, etc). Use the Type Cast function and wire a U8 into the top of the type cast. The output will be the actual U8 number.
- tbob

Inventor of the WORM Global
0 Kudos
Message 5 of 5
(3,109 Views)