Inside the computer, all of our information is made up of binary numbers.
The symbolic number of the table real method:
- The number of symbols is in the form of a complement within the computer
- A positive complement of positive digits
- The complement of a negative number is reversed for its absolute value and then added one gets
For example 7 He is inside the computer is 1111 1001 is so get 7-"111-" 0000 0111-"1111 1000-" 1111 1001
The representation of an unsigned integer:
- Using the original code to list real unsigned integers inside the computer
- unsigned integers default to positive numbers
- unsigned integers have no sign bit
For fixed-length unsigned integers:
The default is a signed type in C, and you can declare integers of unsigned types through unsigned, with special care that only integers can be declared as unsigned integers, and floating-point numbers do not have unsigned types
code Example 1:
#include <stdio.h>intMain () {Charc =-5; Shorts =6; inti =-7; printf ("%d\n", (C &0x80) !=0 )); printf ("%d\n", ((S &0x8000) !=0 )); printf ("%d\n", ((I &0x80000000) !=0 )); return 0;}
This can be done with (bitwise arithmetic) to experiment with the highest bit is 0 or 1
code Example 2:
#include <stdio.h>intMain () {unsignedinti =5; intj =-Ten; if((i + j) >0) {printf ("i + j > 0\n"); } Else{printf ("i + j <= 0\n"); } return 0;}
This code should be carefully analyzed, -10+5 should be a negative number, but for wonder why will print i+j>0. Because when calculating unsigned and signed types, the computer converts the signed symbol to unsigned and then begins the calculation
Example Code 3:
#include <stdio.h>int main () { int0; for (i=9; i>=0; i--) { printf ("i =%u\n", I); } return 0 ;}
This code incorrectly uses an unsigned type, causing the loop to not exit because the unsigned type is a large positive number after you are 0-1
Dfsaf
C-Language advanced-Signed and unsigned 02