当前位置:网站首页>Implicit type conversion (integer promoted part)

Implicit type conversion (integer promoted part)

2022-06-10 07:04:00 Catzzz666

1. The significance of plastic surgery Promotion

The integer operation of expression should be in CPU In the corresponding computing device of ,CPU Internal shaping unit (ALU) The byte length of the operand of is generally int Byte length of , It's also CPU The length of a general-purpose register . This leads to a generic CPU Difficult to achieve 8 The direct addition of bits and bytes ( Although there may be such byte addition instructions in robot instructions ), therefore , Various lengths in expressions may be less than int The integer value of the length , Must be transformed into int perhaps unsigned int, Then it can be sent in CPU Carry out operations .

2. An instance of integer promotion

    char a = -1;
	char b = 1;
	char c = a + b;

char Variables of type can only store 8 Bytes

So in storage a and b Truncation occurred

stay a and b Integer promotion occurs during addition ( Signed numbers complement sign bits , Unsigned complement 0)

Extra one 1 Give up

So it's stored in c The binary code in is 00000000 

The result is 0

原网站

版权声明
本文为[Catzzz666]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/03/202203021200020722.html