LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Ascii string to Hex string..problem

Hi all,
 
I have a problem concerning the asci to Hex conversion. I read an ascii code from my serial port. ( ascii caracters...)  When I select hex display in my string indicator i get the hexadecimal string that i need(0001 2822 2670 0001 2821 2270)... But i only need 3 digits of the Hex code (character 8 (offset 6) character 6(8) and 6 (10) And those characters need to be individually converted to decimals.. But  this can be achived by using the hex string to nr.
 
thnx in advance
 
B Bakels
Labview CLD , Engineer/Manager

Promedes and DSM
using LV 7.1, 8.0, 8.2, 8.5 and 2009 SP1
http://www.promedes.nl
0 Kudos
Message 1 of 5
(3,521 Views)
Hello Bart,

it seems you only need nibbles of the received string...
Two ways:
1. Convert the numbers (=ascii codes) to a hex string and get the appropriate chars by using 'string subset'.

2. Do masking (=AND appropriate bits) and shifting (move upper 4 bits to lower bits, if needed) and do the conversion for each single digit on it's own.

Pretty straight forward number conversion.

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 5
(3,514 Views)
What you see with hex display is actually a representation of the string content. Each character in the representation is not a character in the string, rather it represents a nibble, or half-character (4 bits).
In your example, the string does really contain 12 characters: 00, 01, 28, 22 etc.
Are you sure you need individual nibbles in the string?
Anyway, with the conversion function String to Byte Array you may get an U8 array with 12 elements, with values (in hex) 00, 01, 28, etc., i.e. (in decimal) 0, 1, 40, etc.
From these values you can extract any nibble you want, ANDing a U8 value with hex 0F to get the low nibble, Shifting the U8 by -4 to get the high nibble.
Paolo
-------------------
LV 7.1, 2011, 2017, 2019, 2021
0 Kudos
Message 3 of 5
(3,512 Views)

Hi Bartb,

      IF a "28" always represents an "8", and likewise with the other digits, maybe this would work? 

The For-Loop handles multiple 6-char sequences...

Regards.

Message Edited by tbd on 07-03-2006 03:57 AM

"Inside every large program is a small program struggling to get out." (attributed to Tony Hoare)
0 Kudos
Message 4 of 5
(3,505 Views)

HI

Thnx all for the info.. The Way TDP uses. was the same i idea i got 10 minutes ago :P. I think this is working well... Thnx

 

Bart

Message Edited by bartb on 07-03-2006 01:11 PM

Labview CLD , Engineer/Manager

Promedes and DSM
using LV 7.1, 8.0, 8.2, 8.5 and 2009 SP1
http://www.promedes.nl
0 Kudos
Message 5 of 5
(3,500 Views)