Integer, floating point, character type - C language self-use self-study notes (2)

type of integer

insert image description here
insert image description here

Why define different integer types?

insert image description here
Different integer types occupy different memory sizes and represent different data ranges.
insert image description here
The computer records data through the switching state of the transistor, usually 8 are compiled into a group, we call it a byte.

insert image description here
The switching state of the transistor can be represented by 0 or 1. If it is turned on, it is represented by 1, and if it is turned off, it is represented by 0. - This representation method we call the binary method.
insert image description here
Therefore, a byte, 8 transistors, can have 2 to the 8th power states, each state corresponds to a value, therefore, a byte can represent 256 values.
insert image description here
To represent a larger data range, more transistors are required. However, memory is very precious for computers, so when we know the value range of the data type, we can better choose the integer type and save memory.

Occupies bytes and value ranges

insert image description here
Then use the keyword sizeof in visual studio to measure
the size of sizeof=size+of=something—it can measure the size of bytes occupied by entities. The
insert image description here
size of bytes occupied by different integer types:
insert image description here
insert image description here

data range

A byte is composed of 8 transistors, and the state of the transistor becomes a bit .
insert image description here
Too many are not easy for us to understand, so we try to reduce the number of bits and start analyzing from 3 bits.
3 transistors, what range of values ​​can be represented?
insert image description here
There is a range of values ​​to the power of 2, starting at 0 and ending at 7.
insert image description here
insert image description here
insert image description here
insert image description here
insert image description here
Expressed by addition and subtraction:
add 3 and -3, that is, add 011+101:
insert image description here
use three-bit binary to store data, the highest bit 1 is discarded, leaving only 000
insert image description here

knowledge of complement

Two's Complement Notation: A binary notation in which addition is equivalent to subtraction.
insert image description here

An hour hand has 12 points, that is, its modulus is 12.
insert image description here
How to make the hour hand go back to 0 (12) points?
——Backward 5h
——Forward 7h
insert image description here
insert image description here
insert image description here
insert image description here
insert image description here

range of integer values

The highest bit is the sign bit, so it is 2 to the 7th power and 2 to the 15th power. . . .
insert image description here
If we have determined that it must be a positive number and do not want the highest bit to be used as a sign bit, then use the unsigned keyword to indicate that there is no sign bit, and the highest bit represents a value.
insert image description here

float, char

The integer placeholder is %d
The floating point placeholder is %f
The character placeholder is %c
insert image description here

Guess you like

Origin blog.csdn.net/weixin_45942265/article/details/124450696