当前位置:网站首页>Binary computing

Binary computing

2022-06-24 15:34:00 HLee

brief introduction

Binary is a number system widely used in computing technology . Binary data is used 0 and 1 A number represented by two numbers . Its cardinality is 2, The carry rule is “ On the two into one ”, The rule of borrowing is “ Borrow one for two ”, from 18 Leibniz, a German master of mathematical philosophy in the th century, found that . The current computer system is basically a binary system , Data is mainly stored in the form of complement in the computer . Because the logic of the circuit is only 0 and 1 Two states , there 0 and 1 It's not numerical 0 and 1,0 and 1 It means two different states ,0 Indicates low level ,1 High level . A computer is made up of innumerable logic circuits , adopt 0 and 1 The infinite number of bits and combinations to express information .

Java Built in conversion

stay Java There are several built-in methods to help us carry out various decimal conversions . As shown in the figure below ( With Integer Plastic surgery, for example ):

 Binary system :Integer.toBinaryString(int i)
 octal :Integer.toOctalString(int i)
 Octagon :Integer.toHexString(int i)
 Binary to decimal :
    Integer.valueOf("0101",2)
    Integer.parseInt("11", 2)
 octal :Integer.valueOf("376",8)
 Hexadecimal :Integer.valueOf("FFFF",16)

Use Integer Class parseInt() Methods and valueOf() Methods can convert other base numbers to 10 Base number .

System.out.println("int Maximum positive number :" + Integer.MAX_VALUE);
System.out.println("int The maximum positive binary representation :" + Integer.toBinaryString(Integer.MAX_VALUE));
System.out.println("int Minimum negative number :" + Integer.MIN_VALUE);
System.out.println("int The minimum negative number is binary :" + Integer.toBinaryString(Integer.MIN_VALUE));

System.out.println(" Binary definition printing int The maximum number that can be represented :" + 0b01111111_11111111_11111111_11111111);
System.out.println(" Binary definition printing int The smallest number that can be expressed :" + 0b10000000_00000000_00000000_00000000);

System.out.println("43 Binary representation of :" + Integer.toBinaryString(43));// The result omits the previous 0
System.out.println("-43 Binary representation of :" + Integer.toBinaryString(-43));

// Underline is meaningless , Just for convenience , Can write at will 
int a = 0b00000000_00000000_00000000_00000000_00101011;//0b Represented as binary ,a The decimal equivalent of 43
int a1 = 0b101011;// It's also decimal 43, Just omit the above 0
System.out.println(" Print a Value :" + a);
System.out.println(" Print a1 Value :" + a1);

int b = 0b11111111_11111111_111111111_1010101;// Binary system 43 Add... In reverse 1, become -43, Underline is meaningless 
System.out.println(" Print b Value :" + b);

int i = 0b00000001_00110010_01100111_10101101;// I wrote a decimal 24274861
System.out.println(" Print 10 It's binary i:" + i);
System.out.println(" Print is forced to short Of i:" + (short)i);
System.out.println(" Print short The binary representation of :" + Integer.toBinaryString((short)i));

 result :
int Maximum positive number :2147483647
int The maximum positive binary representation :1111111111111111111111111111111
int Minimum negative number :-2147483648
int The minimum negative number is binary :10000000000000000000000000000000
 Binary definition printing int The maximum number that can be represented :2147483647
 Binary definition printing int The smallest number that can be expressed :-2147483648
43 Binary representation of :101011
-43 Binary representation of :11111111111111111111111111010101
 Print a Value :43
 Print a1 Value :43
 Print b Value :-43
 Print 10 It's binary i:20080557
 Print is forced to short Of i:26541
 Print short The binary representation of :110011110101101

int To short when , Direct interception status 16 Bit conversion

原网站

版权声明
本文为[HLee]所创,转载请带上原文链接,感谢
https://yzsam.com/2021/05/20210511192757675o.html