LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How do I convert 16 bit Binary to ASCII text

I have a 16 bit Binary data string (i.e. 0110000110111000) I need to convert to ascii text using the following format.
 
Note: Name represented by char code set defined in ANSI X3.4 (Std 7-bit ASCII the first bit of each character field will be set to logic zero and the 7-bit ascii code will occupy the remaining 7 bits of the field)
 
Field name             BIT NO            Description
Reserved                   -00- 0           *Note
Character 1                -01-A           MSB
                                   -02-A etc.....
...................................-07-A           LSB
Reserved                   -08-A           *Note
Character 2                -09-A           MSB
                                   -10-A etc .....
...................................-15-A           LSB
 
Is there a simple method I'm missing?
 
 
 
0 Kudos
Message 1 of 23
(11,761 Views)
Its not quite trivial.  You must separate the string into two 8-character strings, then convert to a number, which can then be type casted into a character.  See attached vi.  I noticed that the second substring's first character is not a zero as stated in your definition.  You will get one of those weird characters here.
- tbob

Inventor of the WORM Global
Message 2 of 23
(11,745 Views)

Thanks tbob!

I was on the right path but just needed some expert assistance to get the string into a number.

Let me ask if it would be an easier conversion to go from Hex string to ASCII

 

 

0 Kudos
Message 3 of 23
(11,737 Views)
Slightly easier.  You would have to convert the Hex string to a number using the Hex String to Number conversion function, then use Type Cast to convert to a character.
- tbob

Inventor of the WORM Global
0 Kudos
Message 4 of 23
(11,731 Views)


@tbob wrote:
I noticed that the second substring's first character is not a zero as stated in your definition.


The way I interpreted the problem is that the code should zero out the first bit. You can do that by ANDing it with an appropriate integer. The code in the attached image shows one possibility. There are many ways to do this.

Message Edited by altenbach on 06-20-2006 01:57 PM

0 Kudos
Message 5 of 23
(11,727 Views)


@jdam wrote:
I have a 16 bit Binary data string (i.e. 0110000110111000) I need to convert to ascii text using the following format.

Of course we need to know exactly how your "16 bit binary" data string actually looks like. Your question is a bit ambiguous.

  1. Is it a formatted ASCII string of length 16bytes, containing the letteres 1 and 0?
  2. Is it a 2byte long raw ASCII string, representing the two bytes?
  3. ...?

So far, we have assumed case (1). Case (2) would be trivial. 😉

0 Kudos
Message 6 of 23
(11,720 Views)

Thank you both for your (Quick!) assistance with providing a solution to the problem.

The data is presented in Hex string format of a 16 bit word. 8 words (16 ASCII Characters) comprise the Target Name in the data. Sometimes the data transmission can get corrupted providing an invalid word which was the case with my original submit. (might have just been a fat finger on the kb)

Here are 8 words that comprise the following message   KNID/T192023

19278, 18756, 12116, 12601, 12848, 12851, 8224, 8224

 

 

 

 

 

0 Kudos
Message 7 of 23
(11,717 Views)
OK, that's much easier.... 😉
Message 8 of 23
(11,710 Views)


@jdam wrote:

Here are 8 words that comprise the following message   KNID/T192023

19278, 18756, 12116, 12601, 12848, 12851, 8224, 8224



Your 8 words should give 16 characters.  The last four must be spaces because there are only 12 characters in KNID/T192023.  Also you stated that the data is in hex, but your 8 words are obviously in decimal.  Anyway, here is a vi to decipher the words.

Once again Altenbach has to come up with a simpler way to do things.  Maybe I should send him all my work for reveiw. Smiley Wink

Message Edited by tbob on 06-20-2006 04:16 PM

- tbob

Inventor of the WORM Global
0 Kudos
Message 9 of 23
(11,710 Views)

OK,

tbob and altenbach - You guys make this stuff seem too easy.

Let me pose a new problem - I've already devised a solution but I'd like to see how either of you would approach the problem.

The simplest solution wins a prize! I'll send Two Product Patches to the solution that I like the best. Good Luck!

This is a signed 2's comp problem to describe position (North is positive and south is negative). Input is 2 word hex decimal string array.

The bits are laid out with MSB at the left.

MSB = 2^-1, LSB = 2^-31, Max/Min Value is +/- 5.0000E-01, Resolution 4.6566E-10

2 word message

Field name   BIT NO

MSW       -00- S      Sign

                -01- N      MSB

                -02- N .......-15-N

LSW        -00-N .......-14-N

                -15-N       LSB 

0 Kudos
Message 10 of 23
(11,692 Views)