当前位置:网站首页>Binary conversion problem

Binary conversion problem

2022-07-05 00:26:00 The learning path of Java Rookies


One 、 Introduction to the system

For integers , There are four representations :
Binary system : 0, 1 , full 2 Into the 1. With 0b or 0B start .
Decimal system : 0-9 , full 10 Into the 1.
octal : 0-7 , full 8 Into the 1. In numbers 0 It begins with .
Hexadecimal : 0-9 And A(10)-F(15) , full 16 Into the 1. With 0x or 0X It begins with


Two 、 The conversion of Radix

1. Binary and decimal conversion

Binary to decimal

 Insert picture description here

Convert decimal to binary

The rules : Divide the number by 2 , Until Shang Wei 0 until , Then reverse the remainder of each step , It's the binary system .
Case study : Please put 34 Convert to binary = 0B00100010

 Insert picture description here

2. Binary and octal conversion

Binary to octal

The rules : Starting from the low , Group binary numbers into three bits , Convert to the corresponding octal number .
Case study : Please put ob11010101 Convert to octal
ob11010101 => 0325

Octal to binary

The rules : Put the octal number every 1 position , Turn to the corresponding one 3 A binary number of bits .
Case study : Please put 0237 Convert to binary
Be careful :0 The beginning indicates octal
0237 = 0b10011111

3. Binary and hexadecimal conversion

Binary to hexadecimal

The rules : Starting from the low , Set the binary numbers in groups of four , Convert to the corresponding hexadecimal number .
Case study : Please put ob11010101 Convert to hex
ob1101(D)0101(5) = 0xD5

Hexadecimal to binary

The rules : Put the hexadecimal number every 1 position , Convert to corresponding 4 A binary number of bits .
Case study : Please put 0x23B Convert to binary
0x2(0010)3(0011)B(1011) = 0b001000111011

原网站

版权声明
本文为[The learning path of Java Rookies]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202141125149577.html