Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - How to distinguish unsigned integers from signed integers?
How to distinguish unsigned integers from signed integers?
Signed integers cannot be distinguished in computer memory, but they can be distinguished in programs. The data in the computer is stored in the form of complement and represented in binary. For example, as long as unsigned is added to the type symbol, the default unsigned type is unsigned and Int is signed. In fact, to put it bluntly, defining a signed integer can store positive integers and negative integers, and defining an unsigned integer can only store positive integers.

The number in a computer is expressed in binary, and the leftmost bit is generally used to indicate whether the number is positive or negative, so the number is a signed integer. If the leftmost bit is not used to represent positive or negative, but is connected with the following bits to represent an integer, then it is impossible to distinguish whether the number is positive or negative, and it can only be a positive number and an unsigned integer.

Integers in computers are divided into two categories: unsigned integers.

Integer, also known as unsigned integer), such an integer must be a positive integer; Signed bit integer (signed

Integer), which can represent positive and negative integers.

Unsigned integers are usually used to represent positive integers, such as addresses and indexes. They can be 8 bits, 16 bits, 32 bits, 64 bits or even more. Eight positive binary integers ranging from 0 to 255 (

-1), 16 bits represent positive integers with values ranging from 0 to 65535 (

-1), and the range of positive integer represented by 32-bit binary bits is 0~

- 1。

The difference between signed and unsigned:

Int is signed and unsigned is unsigned.

They actually occupy the same number of bytes, but the signed one needs to arrange a place to represent the symbol of my value, so the absolute value it can represent is half less than that of the unsigned one. For example, if we have an integer of 1 [1] bytes (although this type does not exist), then the unsigned integer is as follows: 0000000 ~1116544.

This is an unsigned range.

A byte is 8 bits,

Signed number, because the first bit is used to represent symbols, then only seven bits can be used to represent the number 0000000 ~1111. Because of the symbol, it can also represent the range: -65438.

1 1 1

~

+ 1 1 1 1

1 1 1。