Get the App
SLTechnology News&Howtos  ›  Servers  › 

Number system and binary conversion

Shulou Source: shulou.com Published: 2022-06-02 15:13:46 09月17日 Update

In computer and programming, our common number systems are binary (B), octal (O), decimal (D) and hexadecimal (H).

Binary number: (starts with 0B)

Binary numbers are also known as machine numbers. in the machine world, only 0 and 1 are known, and binary numbers are represented by 0 and 1. Generally speaking, binary numbers are easy to distinguish and judge, because even a very small binary number is very long, and sometimes we are used to separating every four-digit space from right to left, so it is easy to identify the size of the number.

For example, 14 can be written in binary 1110

25 can be written in binary 0001 1001 (or 11001)

The conversion method is as follows:

As shown in the picture, the conversion from decimal to binary is 1111011. In fact, the conversion to decimal is the same. Until it is zero.

Binary to decimal:

Convert each digital bit separately and sum all the conversion results.

The binary complement is used to record numbers in the computer bytes, and the data is mainly stored in the form of complement in the computer. The binary system in the computer is a very small switch, with "on" for 1 and "off" for 0.

All non-negative integers, the complement is the same as the original

. Decimal negative to binary: "first take the binary value of a positive number, then reverse it, and add 1"

[example]: (- 31) 10 = (1) 2-this is the representation in the computer world, inverted, in fact, the binary representation of-31 is-11111

The binary number of 31 is 11111, take the inverse 00000, add 1 to get 1.

Binary to octal or hexadecimal

1. Convert to a decimal number before using short division.

2. To convert octal, you can use 421 every three digits. For example, the binary of the previous 123 is 0B1 1111011, and the octal is 1 / 4 / 2 / 2 / 1 = 173.

3. Convert hexadecimal and octal in the same way, using 8421 conversion. The binary of 1011 hexadecimal is 4 "2" 1 8 "0" 2 "1 = 7B

Octal number

The octal number is one for every eight digits, and the octal number must start with 0. Octal uses the eight digits of 01234567 to represent numerical values.

The conversion from octal to binary is split, and each number is split into three digits. The binary number is written as OK.

Octal to decimal, the weight is added to ok. As shown in the following picture.

Octal to hexadecimal numbers need to be made using binary or decimal as the middle bridge, and it is easier to make binary as the middle number.

For example:

Octal: 1234567

Conversion to binary is the conversion of each number to a three-digit binary: 001 010 011 100 101 110 111

Then group the numbers from the right into four digits: 0 0101 0011 1001 0111 0111

Then every four digits from the right corresponds to a hexadecimal number: 053977

Hexadecimal number

The hexadecimal number is one for every 16 digits, and the hexadecimal number must start with 0X. Hexadecimal is represented by the sixteen numbers 0123456789ABCDEF.

16music-> 2:

To convert a hexadecimal number to a binary number, simply write a 1-digit hexadecimal number into a 4-digit binary number, and then remove the "0" from the leftmost part of the integer and the "0" from the rightmost decimal part.

For example: 3B.328H = 0011 1011.00110010 1000B = 111011.001100101B

16 music-> 8: it can be written as a binary number, and then converted to octal. As above

3B.328H = 0011 1011.0011 0010 1000B = 00 1111011. 001 100 101 000B

= 73.145O

16 color-> 10: use the right value method, on the ok. Such as 2AF5 =

Example: 1A6.3B8H

= 110 ^ 2 + A10 ^ 1 + 610 ^ 0 + 310 ^ (- 1) + B10 ^ (- 2) + 810 ^ (- 3)

= 116 ^ 2 + 1016 ^ 1 + 616 ^ 0 + 316 ^ (- 1) + 1116 ^ (- 2) + 816 ^ (- 3)

= 419.232422

Decimal number

The conversion of decimal numbers any number system can refer to the short division of binary numbers, which is divided by a few digits. Similarly, I will not repeat it here.

Binary conversion completed

-Yang Guang

Tags: Binary octal binary hexadecimal decimal decimal computer number right beginning complement world integer method machine negative partial division one tiny Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL macOS Apple Shulou Technology vpn