Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to assign a character using ASCII data?

Tags:

c#

char

ascii

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
like image 456
jp2code Avatar asked Jan 06 '10 21:01

jp2code


People also ask

How do you represent characters in ASCII?

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.

How are ASCII values assigned?

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.

How are characters represented using the ASCII character set?

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.

What is the ASCII value of A to Z?

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.


3 Answers

The static modifier is not necessary and you have to explicitly cast your int to a char.

const char FS = (char)0x1C;
like image 121
ChaosPandion Avatar answered Oct 03 '22 19:10

ChaosPandion


I would imagine '\u001C' would work.

like image 41
Marc Gravell Avatar answered Oct 03 '22 21:10

Marc Gravell


const char FS = '\x1C';

like image 43
Seva Alekseyev Avatar answered Oct 03 '22 20:10

Seva Alekseyev