Binary, decimal, octal, hexadecimal conversion table

Table of contents

1. Basic concepts

2 Commonly used bases and representation methods in computer languages

3 Common base operation rules

(1) Binary system: every two enters one

(2) Decimal system: every tenth day

(3) Description of distance from decimal integer to binary:

4. Quick table lookup for hexadecimal conversion


1. Basic concepts

Digit: refers to the position of the digital symbol in a number.
Cardinal number: refers to the number of digital symbols that can be used for digits in a certain carry counting system. For example, the base of the decimal system is 10
Bit weight: the size of the value represented by a 1 in a certain position in the number system (the value of the position). For example, in decimal 230, the bit weight of 1 is 100, the bit weight of 2 is 10, and the bit weight of 3 is 1


2 Commonly used bases and representation methods in computer languages


In computer assembly language, the commonly used bases are binary, octal and decimal.

There are two ways to express the number system. One way is the numerical subscript method. For numbers in different bases, you can add brackets to them and then use numerical subscripts to represent the base:

For example: (110010011111) 2 represents a binary number; (6137) 8 represents an octal number

The other is to use suffix letters to represent the base:

Binary B (binary)
Octal O (octal)
Decimal D (decimal)
Hexadecimal System H (hexadecimal)

3 Common base operation rules


(1) Binary system: every two enters one

The base is 2, and the numerical part is represented by two different numbers 0 and 1.

For example:binaryThe number 1101.01 is converted intodecimal

1101.01(2)=1*20+0*21+1*22+1*23 +0*2-1+1*2-2=1+0+4+8+0+0.25=13.25(10)

So in summary the general formula is:

abcd.efg(2)=d*20+c*21+b*22+a*23+e*2-1+f*2-2+g*2-3(10)

For example: the binary number 100011 can be converted into a decimal number as follows:

There are three 1's in the number, namely one in the sixth digit, one in the second digit, and one in the first digit (from right to left), and then correspond to the decimal number, which is 2 to the 0th power + 2 to the 1st power + 2 to the 5th power. Right now

100011=32+0+0+0+2+1=35

(2) Decimal system: every tenth day

The base is 10, and the numerical part is represented by 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9.

(3) Description of distance from decimal integer to binary:

For example: 255=(11111111)B

255/2=127=====remainder 1

127/2=63======Remainder 1

63/2=31=======remainder 1

31/2=15=======remainder 1

15/2=7========More than 1

7/2=3=========remainder 1

3/2=1=========remainder 1

1/2=0=========remainder 1

789=1100010101(B)

789/2=394 remainder 1 10th place

394/2=197 Yu 0 No. 9

197/2=98 remainder 1 8th place

98/2=49 remainder 0 No. 7

49/2=24 remainder 1 6th place

24/2=12 remainder 0 5th place

12/2=6 remainder 0 4th digit

6/2=3 remainder 0 3rd place

3/2=1 remainder 1 second digit

1/2=0 remainder 1 digit 1

十进制转二进制C++代码

void DtoB(int d) {
    if(d/2)
        DtoB(d/2);
    cout<<d%2;
}




十进制转换二进制python代码

def Dec2Bin(dec):
    temp = []
    result = ''
    while dec:
        quo = dec % 2
        dec = dec // 2
        temp.append(quo)
    while temp:
        result += str(temp.pop())
     
    return result
print(Dec2Bin(62))
#dec要为正整数
=====================================
def bilibili(b):
    t=[]
    i=''
    e=''
    while b<0:
        b=-b
        i='-'
    while b//2!=0:
        a=b%2
        t.append(a)
        b=b//2
    if b!=0:
        t.append(1)
    else:
        t.append(0)
    while t:
        e+=str(t.pop())
 
    return (i+"0b"+e)
 
#b要为整数,效果同Python3.8内置函数bin()

Hexadecimal: every sixteenth day

The base is 16, and there are sixteen numeric symbols. In addition to 0 to 9 in the decimal system, six English letters A, B, C, D, E, and F are also used to represent the decimal numbers 10 to 15.

 

 

The handwriting is a bit ugly, please forgive me. (Hahahahaha)

 

Binary to hexadecimal conversion formula:

An 8-digit sequence, a group of four digits. 8 4 2 1 corresponds to the values ​​arranged from left to right. If it is 1, there is a corresponding value, and if it is 0, there is no corresponding value. Four-digit sum addition conversion (English letters A, B, C, D, E, F represent decimal numbers 10 to 15.)

4. Quick table lookup for hexadecimal conversion
 

 

 

 

 

Guess you like

Origin blog.csdn.net/m0_48565215/article/details/126842598