LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

single ASCII char to byte

Is there a straight-forward way to convert a single ASCII char to a byte.
I know that I can convert a string to an array of bytes.
 
In text-based code, I would simply AND the char with 0x0f, but the booleans do not allow string inputs.
 
 
I am sure that this has been asked before, but I just spent about ten minutes and couldn't find a directly related thread.
 
Any ideas are appreciated.
 
0 Kudos
Message 1 of 8
(5,930 Views)
This should work.
Using LV8.0
--------------------------------------------------------------------
Don't be afraid to rate a good answer... 😉
--------------------------------------------------------------------
Message 2 of 8
(5,926 Views)

Thanks for the try, but I am still in the dark ages of 7.1.

I should probably mention that on all future posts.

 

The way that I do it right now is just use the string conversion of decimal string to number for just one character.

Is that the best way?

 

Perhaps it is my old "cycle counting dinosaur" mentality, but that just seems inefficient for a single byte.

 

Thanks again.

 

0 Kudos
Message 3 of 8
(5,921 Views)
No problem - so a picture should help you..
 
 
 

Message Edited by becktho on 07-19-2006 03:30 PM

Using LV8.0
--------------------------------------------------------------------
Don't be afraid to rate a good answer... 😉
--------------------------------------------------------------------
Message 4 of 8
(5,919 Views)

When I run the cast with a string constant of "5", the output is 53.

When I run a string conversion, I get 5.

 

They both consistently take about 120 ms for 1,000,000 conversions.

 

Any idea why the incorrect value?

 

0 Kudos
Message 5 of 8
(5,910 Views)
Duh
 
The cast is to the numeric value (0x35, 35d) not the value represented by the ASCII char.
 
I guess I will stick with the string conversion.
 
Thanks
 
0 Kudos
Message 6 of 8
(5,906 Views)
The cast operation provided above gives you the ascii-code of the character. So "53" for string 5 is correct (char 5 = 0x35 = 53d).
 
The conversion just converts the string to a number. This means instead of a string you now have a numeric value with the same value.
Using LV8.0
--------------------------------------------------------------------
Don't be afraid to rate a good answer... 😉
--------------------------------------------------------------------
0 Kudos
Message 7 of 8
(5,905 Views)
Sorry - I misunderstood your first post obviously. If you just want a numeric value instead of a string, the conversion function is the way to go. There is not really an alternative to that.
Using LV8.0
--------------------------------------------------------------------
Don't be afraid to rate a good answer... 😉
--------------------------------------------------------------------
0 Kudos
Message 8 of 8
(5,900 Views)