Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and medical aesthetics - How to define signed integers in C language
How to define signed integers in C language
Signed integer is defined in C language: signed int x;; Since signed can be omitted, int x;; You can also define a signed integer variable x.

In C language, the number of signs and unsigned numbers is mainly determined by whether the high bits represent signs (positive or negative). The signed number is the symbol represented by the most significant bit (binary bit), 1 represents a negative number, and 0 represents a positive number. Both positive and negative numbers are stored and used in the form of complement.

(1) Complement of positive number: same as the original code. For example, the complement of +9 is 0000 100 1.

(2) The complement of a negative number: the sign bit is 1, and the other bits are the bit-by-bit inversion of the original code of the absolute value of this number; Then add 1 to the integer. For example, the complement of -7: because it is negative, the sign bit is "1", and the whole is1000011; The original code with the absolute value of the remaining 7 bits of -7 is 000011bit-by-bit inverted to11000; Add 1, so the complement of -7 is11111.