Introduction to base 1
For integers, there are four representations:
Binary:
0,1
,
2
to
1.
Starts
with
0b
or
0B .
Decimal:
0-9
,
10
to
10
.
Octal:
0-7
, full
8-
digit
1.
It starts
with the number
0 .
Hexadecimal:
0-9
and
A(10)-F(15)
, full
hexadecimal
1. It
starts
with 0x or 0X . AF here is not case sensitive.
//演示四种进制
//
public class BinaryTest {
//编写一个 main 方法
public static void main(String[] args) {
//n1 二进制
int n1 = 0b1010;
//n2 10 进制
int n2 = 1010;
//n3 8 进制
int n3 = 01010;
//n4 16 进制
int n4 = 0X10101;
System.out.println("n1=" + n1);
System.out.println("n2=" + n2);
System.out.println("n3=" + n3);
System.out.println("n4=" + n4);
System.out.println(0x23A);
}
}
Binary icon
3. Base conversion ( basic skills )
Introduction to base 1 conversion
Group 1:
1) Binary to decimal
2) Octal to decimal
3) Hexadecimal to decimal
The second group:
1) Convert decimal to binary
Rule: Keep dividing the number by
2
until the quotient is
0
, and then reverse the remainder obtained at each step to obtain the corresponding binary number.
Case: Please convert
34
to binary = 0B00100010
2) Convert decimal to octal
Rule: Keep dividing the number by
8
until the quotient is
0
, and then reverse the remainder obtained at each step to obtain the corresponding octal number.
Case: Please convert
131
to octal
=> 0203
3) Decimal to hexadecimal
Rule: Keep dividing the number by
16
until the quotient is
0
, and then reverse the remainder obtained at each step to obtain the corresponding hexadecimal number.
Case: Please convert
237
to hexadecimal
=> 0xED
The third group
1) Binary to octal
Rule: Starting from the low bit
,
convert
every three digits of the binary number
into the corresponding octal number.
Case: Please
convert
ob11010101 into octal
ob11(3)010(2)101(5) => 0325
2) Binary to hexadecimal
Rule: Starting from the low-order bit, convert the binary number
into a corresponding hexadecimal number
in groups of four digits .
Case: Please convert
ob11010101
into hexadecimal
ob1101(D)0101(5) = 0xD5
Group 4
1) Octal to binary
Rule: Convert each digit
of
the octal number
into a corresponding 3-digit binary number
.
Case: Please convert
0237
into binary
02(010)3(011)7(111) = 0b10011111
2) Hexadecimal to binary
Rule: Convert each digit
of
the hexadecimal number
into a corresponding 4-digit binary number
.
Case: Please convert
0x23B
into binary
0x2(0010)3(0011)B(1011) = 0b001000111011