当前位置:网站首页>[C language] storage of data in memory -1 plastic

[C language] storage of data in memory -1 plastic

2022-06-11 02:12:00 Green abundance is not green

primary coverage :

  1. C The data type of the language
  2. Original code 、 Inverse code 、 Complement code
  3. Plastic surgery Family
  4. Storage of shaping data in memory

  • C The data type of the language

char Character data type
short Short plastic surgery
int plastic
long Long integer
long long Longer plastic surgery
float Single precision floating point
double

Double precision floating point

The meaning of type

  1. Size determines the range of use , Determines the size of the memory space to be opened with this type
  2. Determines how memory space is viewed

  • Original code 、 Inverse code 、 Complement code

The original and inverse complements of positive integers are the same , The rules for the inverse and complement of negative integers are as follows

Original code : Directly translate binary into binary in the form of positive and negative numbers .

Inverse code : Put the original code of The sign bits remain the same , The other bits are in order According to the not You can get it .

Complement code : Inverse code +1 You get the complement .( All the shaping data stored in memory are complements )

Such as four byte integer -1

Original code 10000000 00000000 00000000 00000001
Inverse code 11111111 11111111 11111111 11111110
Complement code 11111111 11111111 11111111 11111111

  • Plastic surgery Family

char { unsigned char , signed char }

short { unsigned short , signed short }

int { unsiged int , signed int }

long { unsigned long , signed long}

char Type is also a type of shaping , because char The characters in will be converted to ASCII The code is stored in memory , and ASCII All codes are integers

Each type of shaping will contain A signed signed and Unsigned unsigned Two types of , The difference between these two types is the sign bit difference in binary  , If not add signed, The default shape is signed type

Signed integers are signed Decorated integer , The highest bit in binary is the sign bit ,1 A minus sign ,0 A positive sign

Unsigned integers are unsigned Decorated integer , The highest bit in binary represents a number

Like binary 11111111, if char, said -177, if unsigned char, said 255;


  • Storage of shaping data in memory

Four byte integer a=20, The complement is expressed in binary as 00000000 00000000 00000000 00010100, Expressed in hexadecimal as 0x00 00 00 14,

b=-10 The complement is expressed in binary as 11111111 1111111 1111111 11110110, Expressed in hexadecimal as 0xff ff ff f6,

And we found that they are stored in memory in reverse , This is related to the storage mode of the compilation environment

  • Big end ( Storage ) Pattern , The low bit of data is stored in the high address of memory , And the high end of the data , Stored in a low address in memory ;
  • The small end ( Storage ) Pattern , The low bit of data is stored in the low address of memory , And the high end of the data ,, Stored in a high address in memory

  So the storage mode in the above figure is the small end storage mode .

for example : One 16bit Of short type x , The address in memory is 0x0010 , x The value of is 0x1122 , that 0x11 by
High byte , 0x22 Is low byte .

For big end mode , will 0x11 Put it in the low address , namely 0x0010 in , 0x22 Put it in a high address , namely 0x0011 in . The small end model , Just the opposite .

原网站

版权声明
本文为[Green abundance is not green]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/03/202203020617192579.html