How do I store an ASCII character to a "char" literal?
The ASCII character I want to use for my special character is the File Separator symbol:
Decimal: 028
Octal: 034
Hex: 01C
Binary: 00011100
// This works in C/C++, but not C#:
static const char FS = 0x1C; // File Separator
ASCII code allows computers to understand how to represent text. In ASCII, each character (letter, number, symbol or control character) is represented by a binary value. Extended ASCII is a version that supports representation of 256 different characters.
It is a code that uses numbers to represent characters. Each letter is assigned a number between 0 and 127. A upper and lower case character are assigned different numbers. For example the character A is assigned the decimal number 65, while a is assigned decimal 97 as shown below int the ASCII table.
ASCII characters may be represented in the following ways: as pairs of hexadecimal digits -- base-16 numbers, represented as 0 through 9 and A through F for the decimal values of 10-15; as three-digit octal (base 8) numbers; as decimal numbers from 0 to 127; or.
Below are the implementation of both methods: Using ASCII values: ASCII value of uppercase alphabets – 65 to 90. ASCII value of lowercase alphabets – 97 to 122.
The static modifier is not necessary and you have to explicitly cast your int to a char.
const char FS = (char)0x1C;
I would imagine '\u001C'
would work.
const char FS = '\x1C';
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With