Video address: https://www.imooc.com/video/21195
Introduction: as we all know, computers are stored in binary. Learning binary well can help us understand how to deal with data and how to store data types in Java. This course will start from the history of binary system to explain binary related knowledge, such as digit value system counting method, decimal conversion, binary decimal, etc. This paper introduces the integer type, floating point type and character type in Java. You can also see how BigInteger, BigDecimal are used, ASCII unicode relationship, etc
Chapter 1 understand the mathematical basis of computer binary
This chapter will lead you to understand the basic concepts, development history, use scenarios, analyze the advantages and disadvantages of binary, and introduce all courses
1-1 binary past and present (08:26)
Chapter 2 system in computer
This chapter introduces the basis of binary system and other base system - bit value system counting method. And the conversion between various bases in Java. Bit operation is to directly operate the binary bits in memory, explain this basic operation mode and experience the efficiency of bit operation
2-1 bit value system counting method (12:14)
2-2 base in Java (15:55)
public class BinaryTest { public static void main(String[] args) { // Binary int bin = 0b1100010; // octal number system int oct = 0142; // hexadecimal int hex = 0x62; // decimal system int dec = 98; // Prefix is the number 0, not the letter O // The English letter b x is case insensitive // Use specified number in specified base // The underlying storage is in binary form // Java uses decimal by default, and the output and display are all in decimal form System.out.println("2:" + bin); System.out.println("8:" + oct); System.out.println("16:" + hex); System.out.println("10:" + dec); } }
public class BinaryTest { public static void main(String[] args) { /*// Binary int bin = 0b1100010; // octal number system int oct = 0142; // hexadecimal int hex = 0x62; // decimal system int dec = 98; // Prefix is the number 0, not the letter O // The English letter b x is case insensitive // Use specified number in specified base // The underlying storage is in binary form // Java Decimal is used by default, and the output display is in decimal form System.out.println("2:" + bin); System.out.println("8:" + oct); System.out.println("16:" + hex); System.out.println("10:" + dec);*/ int num = 98; /*System.out.println("2:" + Integer.toBinaryString(num)); System.out.println("8:" + Integer.toOctalString(num)); System.out.println("16:" + Integer.toHexString(num));*/ /*System.out.println("2:" + Integer.toString(num, 2)); System.out.println("8:" + Integer.toString(num, 8)); System.out.println("16:" + Integer.toString(num, 16)); //----------------------- System.out.println("------------------"); System.out.println("5:" + Integer.toString(num, 5)); System.out.println("36:" + Integer.toString(num, 36)); System.out.println("37:" + Integer.toString(num, 37)); System.out.println("100:" + Integer.toString(num, 100));*/ System.out.println(Integer.parseInt("1100010", 2)); System.out.println(Integer.parseInt("62", 16)); System.out.println(Integer.parseInt("2q", 36)); } }
2-3 bit operation (12:47)
Chapter 3 storage of basic data types
This chapter introduces the concept of bit and byte, and introduces the. class file and Jvm in Java. In the part of basic data types, it mainly introduces the integer and floating point types: integer storage, multibyte size end problem, symbol problem, complement problem. Addition and subtraction shift operation of complement; binary decimal, storage principle of floating-point number IEEE754. And two problems are solved in Java: BigInteger introduced in integer value range problem and BigDecimal introduced in precision loss problem. In addition, the relationship between ASCII and unicode and the storage of boolean are introduced
3-1 integer types in Java (10:36)
public class BigIntegerTest { public static void main(String[] args) { BigInteger b1 = new BigInteger("29"); BigInteger b2 = new BigInteger("1010", 2); BigInteger b3 = BigInteger.valueOf(33l); System.out.println(b1.toString()); System.out.println(b2.toString()); System.out.println(b3.toString(2)); } }
public class BigIntegerTest { public static void main(String[] args) { BigInteger b1 = new BigInteger("29"); BigInteger b2 = new BigInteger("1010", 2); BigInteger b3 = BigInteger.valueOf(33l); /*System.out.println(b1.toString()); System.out.println(b2.toString()); System.out.println(b3.toString(2));*/ BigInteger add = b1.add(b2); BigInteger sub = b1.subtract(b2); BigInteger mul = b1.multiply(b2); BigInteger div = b1.divide(b2); System.out.println(add); System.out.println(sub); System.out.println(mul); System.out.println(div); } }
3-2 binary decimals (08:28)
3-3 IEEE754 and BigDecimal (12:36)
public class BigDecimalTest { public static void main(String[] args) { /*BigDecimal b1 = new BigDecimal("0.1"); BigDecimal b2 = new BigDecimal(0.1); System.out.println(b1.toString()); System.out.println(b2.toString()); BigDecimal b3 = new BigDecimal(0.1 + ""); System.out.println(b3.toString()); BigDecimal bigDecimal = BigDecimal.valueOf(0.1); System.out.println(bigDecimal);*/ BigDecimal b1, b2; b1 = BigDecimal.valueOf(0.3); b2 = BigDecimal.valueOf(0.1); BigDecimal div1 = b1.divide(b2); System.out.println(div1); BigDecimal div2 = b2.divide(b1, new MathContext(5, RoundingMode.HALF_UP)); System.out.println(div2); } }
Character and Boolean types in 3-4 Java (09:24)
ASCII
Chapter 4 review and summary
Review and summarize all the contents mentioned in this course
4-1 review and summary (05:08)
This article is based on the platform of blog one article multiple sending OpenWrite release!