LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

How to convert Char to Int

I'm using serial port to transmit and receive data. The problem is the convertion from char to integer. For example I receive an 'A' and I want to convert this 'A' into int count = 65 decimal.

Paco
0 Kudos
Message 1 of 3
(5,947 Views)
Hi, use 'scan' function, below is example

s = "ffff";
n = Scan (s, "%s>%x[b2]", &a); /* result: a = 65535, n = 1 */
"Only a life lived in the service to others is worth living..." - Albert Einstein
Message 2 of 3
(5,941 Views)
Hello,

The previous reply shows how to convert ASCII-formatted hexadecimal value to a (decimal) variable.
The question however seems to show that it want to convert a character to its ASCII code. This can be done more easily with prototyping e.g.
char Text = 'A';
int Value;
Value = (int)Text;

I have added a small example that shows some of the scanf codes (but often documented as printf codes) and where I have added a line where the first character of an input text is converted to its ASCII code.

Succes, Jos
0 Kudos
Message 3 of 3
(5,931 Views)