# How can you specify an unsigned binary file

Binary Learning Notes (In fact, it's useless, just keep it to yourself)

Introduction to Binary

Only 0 1

Advantage:

1. Simple binary state

2. High reliability and stability

3. Simple operation rules and simplified design

4. Strong versatility

Binary calculation

Positive binary file

Decimal to binary (divide by two to 0)

Rule: Divide by two and take the rest

Or divide a number into 2 to the power of n and add up

55=32+16+4+2+1

2^5+2^4+2^2+2^1+2^0

110111

Negative binary file

-77 -1001101

Use a binary bit as a symbol to store a symbol

int 32 bit char 8 bit

char -77 ——> The highest bit is regarded as the sign bit. 1 is negative and 0 is positive.

1100 1101 (original code The original code is wrong in the calculation formula)

Invert the original code

1011 0010 (all inverted with the exception of the sign bit)

1011 0010 + 1 = 1011 0011 (inverse code plus 1)

The complement code is saved and adding the complement code will not result in an error

8-bit binary file

16+（-13）

16 0001 0000

-13 binary 1st original code 1000 1101

2. Inverse code 1111 0010

3.'s complement 1111 0011

Original code addition

0001 0000 +

1000 1101 =

1001 1101 (the result is wrong)

Add supplement

0001 0000 +

1111 0011 =

1 0001 0011 (only 8 digits, remove the most significant bit, the result is correct)

It is stipulated that the original code, its own complement and the complement of a positive number are the same

Storage of decimal binary and floating point data

Decimal binary 2 ^ -6

Save floating point type, precision float 32 bit, only 6-7 bit accurate

32 bit

The most significant bit sign bit 1 bit stores the sign 1 is a negative number 0 is a positive number

8 bits relate to the mantissa bit 1 + 172 ——> save to the exponent bit offset (127)

23 bit mantissa bits

Move 1.1001001 one place to the left

1.1001001 * 2 ^ 1 // Binary exponential form

10 hex

110=1.10*10^2

-3.1415

1 1000 0000 1001 001 0000 0000 0000 0000

——> 127 8-bit exponent bits ——> - 127 ~ 128 + 2 ^ 7-1

*/

Floating point binary

1. First calculate the decimal binary number. 2. Convert the decimal binary number to exponential form. 3. Store the sign bit of the decimal number in the first digit of the floating point. 0 is a positive number, 1 is a negative number. The exponent part is added with an offset and stored in 8. The exponent bit stores the decimal part of the binary exponential form in the mantissa. If the number of digits is insufficient, fill the PS with 0 to convert the decimal form to the exponential form. The rule is to move the small one to the right of the first 1. If you move a few digits to the left, multiply by the power of 2.

Additional information on secondary studies

Data ---> binary

Division efficiency Computer division is realized by subtraction

Use of binary ---> PS Mito binary mode

Important points: Calculating the binary number (decimal number to binary number)

1. Daily use is decimal decimal decimal -> binary storage

3 (D) 11 (B)

But different bases can represent one thing

2.Counts (calculation method)

3rd integer (must be positive and negative) floating point (understand)

4. Base conversion binary base 8 base / 16 base 10 base

Binary (the way the computer is stored) (not used in the code)

Octal / hexadecimal instead of binary (can be converted directly into binary)

Decimal (usually used)

1. Integer binary file

1.1 Positive numbers

int char (-128 ~ 127 0 ~ 127 each integer corresponds to an ASCII character)

170 123

Divide by 2 to find the rest

170 in binary 10101010

123 binary 1111011

int 32-bit complement

0000 0000 0000 0000 0000 0000 0111 1011

char 8-bit binary file

0111 1011

unsigned unsigned

signed

(signed) int

unsigned (int) unsigned means unsigned int by default

unsigned char

(signed) character is signed by default

1.2 Negative numbers

Signed can store negative numbers

Negative number 3-2 ---> 3 + (- 2)

The highest bit is used as the sign bit to store the sign. 0 means positive number 1 means negative number

char as an example

3 0000 0011

-3 1000 0011 (the most significant bit is used as the sign bit) ---> If you use this as a binary file, you will get errors when calculating negative numbers

Original code

The inverse code 1111 1100 (the original code with the exception of the sign bit, all 1 becomes 0 and 0 becomes 1)

Complement code 1111 1101 (complement code plus 1)

An integer negative binary number is stored in the complement

The reason for the complement is to make sure the binary calculation is correct with negative numbers

Invert plus 1 code

Special case

1. Binary of -128 in char

Inverse code 1111 1111 original code -> 1000 0000 -128

Complement 1000 0000

2. unsigned to store negative numbers

----> Computer uses binary data to process data (no error doesn't mean there is no error)

Follow the grammar (there is no point in considering the wrong code)

Signed and unsigned bits are the same

Binary is not positive or negative

Format placeholder -----> printing method

Save the binary file without distinguishing between positive and negative, the method of analysis is different, the processing result is different

% u unsigned decimal number

% d signed decimal number

% x unsigned hexadecimal integer

% o unsigned octal integer

unsigned int x = -3;

unsigned int x = 0xfffffffd; // If the code is expressed in hexadecimal, add 0x before the octal and add 0

// Indicates that the data will be treated as an unsigned integer

// is the computer checking the binary?

You can try to print the float type with% d (you can print without error, but the result will be wrong).

-3 original code

1000 0000 0000 0000 0000 0000 0000 0011

1111 1111 1111 1111 1111 1111 1111 1100

1111 1111 1111 1111 1111 1111 1111 1101

1byte = 8bit

The division is slower. Divide an integer by 2 >> 1. Shift one bit to the right. Divide by 2

Data out of range ---> overflow

char ch = -128; 1000 0000

ch--; 0111 1111 ---> 127

2. Floating point binary storage (understand)

float double (1 + 11 + 52)

Float memory data area -1.7 * 10 ^ 38 ~ 1.7 * 10 ^ 38

float 4 bytes 32 bit (signed) 1 + 8 + 23

1 bit sign bit

8-bit exponent bit

23 bit mantissa bits

-7.88

method

1. Convert to binary decimal first

Icon retention

The integer part is calculated using the integer binary method

The decimal part is multiplied by 2 and rounded from top to bottom to the right of the decimal point

-111.11100001

The decimal point is shifted to the right of the first 1

-1.1111100001 * 2 ^ 2 exponential form, shift by N bits to the left * 2 ^ N.

The index is stored in 2 to 8 places. The calculation method is special. Index + offset

2 +127--->129 1000 0001

Add an offset 2 ^ (number of exponent bits-1) -1

8-bit exponent 2 ^ 8 256 half the negative number and 0 half the positive number

The range of the exponent bit from float -127 ~ 128

0000 0000 --->-127

0000 0001 --->-126

.....

1000 0000 --->1

1000 0001 ---->2

Mantissa place The content after the decimal point is followed by 0

1 1000 0001 111 1100 0010 0000 0000 0000

Floating point storage rules --->

finally

1. Floating point storage is not accurate enough

== Compare x == 4 integer

Floating point types generally don't need == to give them a range

d <= 4.001 && d> = 3.999

Double and Float get the same value, but the stored value is different

Float is fast, precision is not high, float or double

**** Stored data are approximate

3. Base conversion

Decimal to Binary ---> Divide by 2 to find the remainder

Decimal to octal, divide by 8 to find the remainder

Divide by 16 to find the remainder (a ~ f means 10 ~ 15). A ~ F can be capitalized

Hexadecimal ---> decimal

N to decimal

0xAF ---> Start from right to left at 0 and label one after the other

Each digit * N ^ designation (sum)

Conversion between binary and hexadecimal

0xAF

Binary -> 1010 1111

One hexadecimal to 4 binary

Binary to hexadecimal

1100 0000 1111 1100 0010 0000 0000 0000

-> C0FC2000 Four bits to one bit -> 0xC0FC2000

One octal to 3 digits, 3 digits to octal

Calculate by writing ---> final conclusion write everything in hexadecimal form -> send the result directly

1. Calculate binary (calculate 8 bits with char)

98

-76

Choose to do

2. Calculate binary (float 32-bit binary calculation)

-3.625

short (int)

long (int)

2018.05.13 21:24:13

Reprinted at: https://www.cnblogs.com/Yuuki-/p/9033416.html

- What are communication and leadership
- What is the location of Grandthum
- Samsonite luggage comes with a lifetime guarantee
- A co-founder is a title
- How is success in music determined
- What are some beautiful Odia novels
- How do you feel about unemployment?
- How does a material transform into ductile
- The Bible either permits or condemns abortion
- Does energy management have any scope in the US?
- Is the magic of Dynamo's Steven Frayne real
- What are good resources for learning Pythonic
- Can you love without being in love
- Can you send a ship via TikTok
- How is Basara IIIT 1
- I do not forget what should I do
- Who can use FASTag
- How to Hire a Great VP of Sales
- What is the cheapest type of fence
- What are the literary fictions with leopards
- How do data analytics companies work
- An office manager is a secretarial job
- Who colonized Jamaica How was it colonized
- Why are my employees assholes