Get the ascii value for a char, Ord equivalent in C++
In delphi exist a function called Ord
which Returns the ordinal value of an ordinal-type expression.
for example you can retrieve the Ascii value for a char in this way
Ord('A') return 65
Ord('a') return 97
in C++ which function i must use to get the ascii value for 开发者_StackOverflowa Char.?
A simple int a = c;
where c
is a char
should work.
A char holds the ASCII value.
You can cast it to an integer if you prefer.
Typecast it using ascii = (int)character
.
char c = 'a';
printf("%d", c);
this would do...
if you need to use the ascii value for numerical operations, use
char c = 'a';
int i = (int)c;
how about
#include <ctype.h>
int LOrdValue = __toascii('a');
you can do
char a ='A';
int b = a&0b11111111;
this should give 65
精彩评论