Reputation: 337
How to convert integer to char and vice versa in "Dynamic C".
Use VB.NET as bellow:
Dim i As Integer
Dim c As Char
' Integer to Character
i = 302
c = ChrW(302)
Debug.Print(c) 'Result: Į
' Character to Integer
Dim j As Integer
j = AscW(c)
Debug.Print(CStr(j)) ' Result: 302
Thanks
Upvotes: 0
Views: 1767
Reputation: 34
Why dont you use an other type like uint16_t that can be used for UCS2 ? I mean char is used for ascii and extended 0-255 ~ uint8_t, if you need more dont use char.
uint16_t c=302;
Upvotes: 0
Reputation: 33181
If you want to parse a character such that '1' becomes the integer 1, you can use itoa
and atoi
.
If you want to convert between the the ascii values and their characters, that's even easier. Simply cast the int to a char or the char to an int.
Upvotes: 1
Reputation:
Since both int and char are integer types, you can simply assign an appropriately-valued integer to a char and vice versa:
int i = 65; // 'A'
char c = 'B'; // 66;
int cAsInt = (int)c; // 66 = 'B'
char iAsChar = (char)i; // 'A' = "65"
Upvotes: 1