Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Basic knowledge sharing related to java binary system

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article focuses on "java binary related basic knowledge sharing", interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Now let the editor to take you to learn "java binary related basic knowledge sharing"!

Description

There are specifications for everything. When it comes to JAVA, you will mention two specifications, the JAVA language specification and the JVM specification. JAVA language specification mainly defines JAVA syntax, variables, types, grammar and so on. JVM specification mainly defines Class file type, runtime data, frame stack, startup of virtual machine, instruction set of virtual machine and so on.

The JAVA language specification mainly defines what is JAVA language.

JVM specification mainly defines JVM internal implementation, binary class file and JVM instruction set and so on.

Internal representation and storage of numbers in the specification

Eight basic data types of JAVA:

Plastic surgery: byte,short,int,long

Floating point: float,double

Boolean: boolean

Character type: char

Number of bits occupied by data type

Number of digits occupied by data type int32bitshort16bitlong64bitbyte8bitchar16bitfloat32bitdouble64bitboolean1bit

Remarks: 1 byte = 8 bits (1 byte = 8bit)

Representation of integers

Source code: the first bit is the symbol bit (0 for positive, 1 for negative).

Inverse code: the symbol bit does not move, the original code is reversed.

Negative complement: the symbol bit is fixed, the inverse code is added by 1.

Positive complement: same as source code.

Remarks: benefits of complement:

The complement can be used to express 0 without any ambiguity.

Complement can well participate in the binary operation, complement plus symbol bits to participate in the operation, which is much easier.

Floating point representation

In the figure above, we learned that both Float and Double support IEEE 754

Let's use float to illustrate:

The IEEE745 single-precision floating-point format has a total of 32 bits and contains three constituent fields: the 23-digit decimal fraction, the 8-bit offset index, the 1-bit symbol s. These fields are stored successively in a 32-bit word and encoded. The 0:22 bit contains the 23-digit decimal f, the 23:30 bit contains the 8-digit exponent e, and the 31st bit contains the symbol s.

A real number V can be expressed in the form of V = (- 1) s × M × 2e in IEEE 754 standard, which is explained as follows:

The sign s (sign) determines whether the real number is positive or negative, and the sign bit of the numeric value 0 is specially handled.

The effective number M (significand) is a binary decimal, and the value range of M is 1 ≤ M < 2 or 0 ≤ M < 1.

The exponent E (exponent) is a power of 2, and its function is to weight floating-point numbers.

Symbol bit index place decimal place 1 place 8 bit 23 bit

For example, according to IEEE745, calculate the value of a single-precision floating point of 110000010000000000000000000000.

Solve the problem:

110000010001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010001000100000000000000000000 symbolic place index Mantissa is not all zero so decimal places are appended 11100000101.00100000000000000000000 ^ (130-127) (2 ^ 0 + 2 ^-3)

Conclusion:-1 * (2 ^ 0 + 2 ^-3) * 2 ^ (130-127) =-9

Similarly, you can also verify that the binary form of the decimal floating point number 0.1 is correct, and you will find that 0.1 cannot be represented as a finite number of binary bits, so the representation in memory is the result of rounding, that is, 0x3dcccccd, decimal 0.100000001, resulting in an error of 0.000000001.

The concept of binary

The commonly used bases are binary, octal, decimal and hexadecimal, and decimal is the most important form of expression.

Binary is 0 and 1; octal is 0-7; decimal is 0-9; hexadecimal is 0-9+A-F (uppercase and lowercase).

Bit operator

Bitwise and (&)

If both are 1, the result is 1:

0: 00, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1.

Usage:

Zeroing: if you want a unit to clear zero, then make it all binary to 0, as long as you want to match with a number that is all zero, the result is zero.

Take a middle finger location of a number: find a number that corresponds to the bit to be taken by X, the corresponding bit of the number is 1, and the other bits are zero. The finger location in X can be obtained by "and operation" with X.

For example, if you set Xbox 1010 1110, take the lower 4 bits of X and use X & 0000 1111 = 0000 1110 to get it.

Bitwise or (|)

As long as one is 1, the result is 1:

0 | 0: 0 | 1: 1: 1 | 0: 1: 1 | 1: 1 |

Usage: commonly used for some position 1 of a data; find a number that corresponds to the bit of X to set 1, the corresponding bit of the number is 1, and the rest bits are zero. This number is similar to X or can make some position 1 in X.

For example, you can get the lower four position 1 of Xbox 1010 0000 with X | 0000 1111 = 1010 1111.

XOR operation (^)

* if the two corresponding bits are "different" (with different values), the result is 1, otherwise it is 0: *

0 ^ 0 = 0; 0 ^ 1 = 1; 1 ^ 0 = 1; 1 ^ 1 = 0

Usage:

Make the special position flip: find a number that corresponds to the bit of X to be flipped. The corresponding bit of this number is 1, and the other bits are zero. This number can be obtained by XOR corresponding to X; for example, X is 1010 1110, which flips X 4 bits lower, and you can get it with X ^ 0000 1111 = 1010 0001.

Different from 0 or keep the original value for example: X ^ 0000 0000 = 1010 1110

The method of exchanging the values of two variables: 1, with the help of the third variable: C; B; B; C; 2. The use of addition and subtraction to realize the exchange of two variables: B, B, A, B, B,

Reverse operation (~)

For a bit-by-bit inversion of a binary number, it will change from 0 to 1, 1 to 0: ~ 1 to 0; ~ 0 to 1.

Left shift operation (> >)

Each bit moves the specified number of bits to the right. After moving to the right, the prominent bit on the left is filled with zero. The bits moved out of the right are discarded

Each bit moves the specified number of bits to the right. After moving to the right, the prominent bit on the left is filled with zero. The bits moved out of the right are discarded

For example:-14 > 2

That is,-14 (1111 1111 1111 0010) > > 2

= (0011 1111 1111 1111 1100)

= 1073741820

Description:

0x80000000 is a hexadecimal representation of a number, converted to a binary representation of 1000000000000000000000000000

The priority of operation, shift operation is higher than logic operation, > higher than &

Bit logic and operation 1: 1 = 1, 0: 1 = 0

Move unsigned to the right, remove part to discard, and fill in 0 on the left.

At this point, I believe you have a deeper understanding of "java binary-related basic knowledge sharing". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report