storing hexadecimal digit to type char

Thread Starter

anukalp

Joined Jul 28, 2018
146
I have a question, unsigned char occupy the 1 byte of memory to store single character.

Code:
    unsigned char a = 'A';
    unsigned char b = 250;
    unsigned char c = 0x31;
    unsigned int d = 0x32;
Here a is character variable . The value of a is 'A'. It occupy the 1 byte of memory

What does character variable store when we assign decimal and hexa decimal digit ?
 

Papabravo

Joined Feb 24, 2006
13,972
Variable b has in it a 0xFA which is 250 decimal and is also the character 'ú'
Variable c has 0x31 which is also the character '1'
Variable d has 0x32 which is also the character '2'
 

WBahn

Joined Mar 31, 2012
25,928
I have a question, unsigned char occupy the 1 byte of memory to store single character.

Code:
    unsigned char a = 'A';
    unsigned char b = 250;
    unsigned char c = 0x31;
    unsigned int d = 0x32;
Here a is character variable . The value of a is 'A'. It occupy the 1 byte of memory

What does character variable store when we assign decimal and hexa decimal digit ?
It's helpful if you at least make mention of what programming language you are talking about. It might be a good guess that you are talking about C, but engineering is not about guessing.

What is stored in the variable is a bit pattern that represents a binary integer. The C standard requires that a char occupy no less than 8 bits, but it could occupy more (I'm not aware of any current compilers for which this is the case, but historically there are numerous examples).

The 'A' is a mathematical expression which evaluates to the character code for the upper-case letter 'A' in the execution character set, which is usually ASCII. In that case it is the decimal value 65.

0x31 is nothing more than a representation of the decimal value 49, which 0x32 is a representation of 50. In ASCII, '0' evaluates to 49 or 0x31, so using any of the three of them in any expression in which an integer literal is allowed would produce identical results.
 
I have a question, unsigned char occupy the 1 byte of memory to store single character.

You need to go back in time: https://www.ascii-code.com/

You had 0-127, 128 was the parity bit.

Control characters were just that. They rang the bell. Did a form feed. Started and stopped the paper tape reader etc.

0 was a null. It just took up time. it was necessary to give time for a mechanical carriage to return to position 1, assuming 80 columns. 80x24 was normal for CRT's.

You had 80 and 132 column printers. Some CRT's could display 132 columns.

You can also look up punched cards https://en.wikipedia.org/wiki/Punched_card and paper tape.
 
Top