Why does int occupy 4 bytes? Why is a byte 8 bits?

I don't know if you have ever thought about such a problem, why a byte is 8 bits, maybe there are some friends who don't know what I am talking about, it doesn't matter to look down.

The first explanation (history) is that IBM designed a set of 8-bit EBCDIC codes for System/360, covering numbers, uppercase and lowercase letters and most common symbols, and compatible with the 6-bit BCDIC codes widely used in punch cards.

The second explanation is that we should all know the binary system. In the ASCII table, all the characters stored in the ASCII table are in 8-bit binary form. From 0 to 127, 128 characters are used. The last one is 01111111 is the delete key. If you add one more, it will not be 8 bits.

Above, I solved why a byte is 8 bits.

Let’s talk about why int occupies 4 bytes

The first explanation is that int is said to be defined according to different compilers. Different compilers have different bytes of int, but most compilers int account for 4 bytes.

The second explanation is that when the operating system is 16-bit, int is 2 bytes, and when the operating system is 32-bit, int is 4 bytes. Since 32-bit systems used to be the mainstream, it is actually a 64-bit system now because of compatibility. Consider that int is also 4 bytes.

The number of bits occupied by the data type in the memory is actually related to the number of bits of the operating system and the compiler (the number of bits supported by different compilers may vary).

Guess you like

Origin blog.csdn.net/weixin_44126152/article/details/102898592
Recommended