Basic Java Notes (3) binary and binary conversion

Source: Internet
Author: User
Tags binary to decimal decimal to binary

---restore content starts---

In-process

In general life, we have been in the application of the decimal, is every ten into one, and today we want to contact is, computer programming commonly used in the system! First of all we need to know that the computer internal operations using binary, that is, every binary!

1. What is a binary?

That is, only 0 and 1 move forward whenever a value of 2 is encountered.

2. Why is there a binary inside the computer?

This is from the hardware, the computer is how to store data, to know that our network transmission, you want to chat with others, you are far away, in the end is how to let him receive your chat content? There is a network cable can also say that the past, after all, network cable link terminal We do not know where to go, discouragement is the world is a network cable link. But why is it possible to chat content when wireless?

Attached: Our network transmission is mainly more our computer from the application layer to the physical layer of hardware equipment, the physical layer of data link layer data frame into the corresponding signal form of the transmission medium, such as optical signal, electromagnetic wave signal and then by the router communication, as long as not the same network, we have to rely on routing transmission. In this way, it is far away, simply say, why do we use the computer binary, exactly what is the relationship with the above? It is because we use electricity and light to transmit the data, then in the hardware equipment to identify these electrical and optical transmission is very troublesome, such as to give him what shape is to represent what, this is too complex and transmission is too unstable in the beginning to be eliminated from the idea, until later the great gods have specified the wavelength of the ascending type represents 1 The wavelength is reduced to indicate that the 0 parallel is unchanged, because only these two forms, so the use of binary is the most suitable, so the internal computer is a binary!

Note: In our Java tutorial It is generally said that our computer transmission of electrical signals is 1 off is 0 This is an image of the argument. After all, we understand the binary and how he does it. The count is not much of a necessity.

So let's simply simulate a way that the Java tutorials are most often understood

Look at the picture, power on status identification 1 different electrical representation 0.

In summary, you simply understand: this is determined by the work of the computer, the computer to do the actual operation of the circuit, the logic of the circuit is only 0 and 12 states, where the 0 and 1 is not the number of 0 and 1,0 and 1 is the two different states, 0 is low, 1 indicates high level. Because computers are made up of countless logical circuits, information can only be expressed based on the infinite number of digits and combinations of 0 and 1. So the binary is closest to the computer working mode, but also the computer can read directly, other high-level languages need to be escaped into machine language.

What we need to learn is not how computers collect electrical and optical signals, but what computers are commonly used in: 1. Decimal 2. Binary 3. Octal 46 Binary

1. Decimal every ten in a 1 2 3 4 5 6 7 8 9 to 10 How does that mean 10? He went into the thought

2. Binary every binary one is 0 1 to 2 He is also only 10 in binary this means 2 is not 10 OH

3. Eight binary octal one is 0 1 2 3 4 5 6 7 when he was 8, he entered a 10, which means the decimal 8.

4.16 hex Hexadecimal is 0 1 2 3 4 5 6 7 8 9 A (Ten) B (one) C (+) D (+) E (+) F (15) 6 Not 6 The numbers are not enough, the letters come together.

Know what the use of these systems, do not know if you have this question? Why do you study it?

At present, we have to learn the data type and bit operations are required in the knowledge of the system, in particular, what kind of knowledge? is the incoming conversion to be told!

Conversion: It is the conversion between these binary, the computer internal computing is binary, then in the end we open the computer system, he is what principle, so that we can do decimal operations? How to do this, this is the main content for today!

Do not understand the octal and hexadecimal does not matter, first try to understand the meaning, the other specific number conversion value can be ignored, and so looked at the decimal to binary system and look back again!

The first thing we need to know is the octal system:

The eight-in-one feature is every eight. So, here's a binary number: 0111 Open the computer and choose the programmer type. (Will not choose their own Baidu)

BIN: Binary hex: Hex OCT: octal DEC: Decimal!

Yes, this number represents 7.

Where are we looking? Binary number: 1000

Note: is the OCT writing 10 a forward?

So octal we use binary generally this way to convert three bits to represent an octal one!

Hexadecimal Similarly, I will not use the computer, directly to you to write

Binary turn 16 binary:

Because the binary 1111 table is 15 and Hex is 16 in one, so binary hexadecimal is four bits represents hexadecimal one bit.

So understand this, let's do a few exercises:

00010001 calculated his 16 binary and octal

Binary: 000010001

Octal: 000 010 001

Final Answer: 0 2 1 so yes: 21

Crouching groove, how to make this number is 21 how I calculate with the computer 21 is not the answer, so began to panic!

This is a use of the system is not familiar with the cause, note that we are binary to the octal system, we do not look dec this is a decimal. If you're like me, WIN10 First, click the Oct and look at the bin.

There's nothing wrong with that! Then we through this conversion also understand a point to remember: The system will not we use the computer to chant, anyway, it is not commonly used, the algorithm can remember, remember we use the computer, really want to find algorithm on Baidu Bai!

Okay, there's nothing wrong with the octal system, let's look at the hex example:

bin:00010001

hex:0001 0001

Conversion: 11

Ming Bar, it is to split the binary system and then calculate their values, so that the rapid conversion can be achieved!

decimal Turn binary:

Look at the above conversion estimates have a question 0001 how do you know it's 1? This is not a mess, I do not know why 0001 is 1. Don't worry, learn decimal to binary system, no matter how many systems you can understand in a moment!

First learn decimal to binary system we use the most primitive expression to learn: decimal to binary system is always divided by 2 decimal, after the end is 1 then the last one is 1 if the last one is 0, from the bottom to the top! Note that the original algorithm for hexadecimal and octal are common, the main is the octal and hexadecimal, to split such as Hex 2F two digits, to know that a hexadecimal representation of 00004 bits so divided by 2 and then according to the position of the combination of 0 and 18 is also the same, Octal is a three bit, which is different from hexadecimal, press three poorly transposition!

Example: We are now going to convert 10 to 2 binary

Parse: is always divided by 2 at the first 10/2=5 no remainder, so this position is 0 then the number 5 divided by 2 5/2=2%1 so this position is 1 get 2, at this time 2/2=1 so the final answer: 1010

Now we're doing two examples.

converts the decimal 25 to a binary number:              2 |        1                ------             2 |        0                ------              2  | 6       0                  ----               2 | 3       1                         ------                   1 The              bottom-up is the binary number:

Then learn the decimal, then decimal to binary system how to calculate it? integer binary multiplied by value 2 the power of the number of decimal binary 2 the negative power of the second and then add in turn!

As an example: 0101-Turn decimal

This is the conversion, if you are a novice, to see my information, estimated that my information is a bit for my personal writing, then I'll find you a few articles to learn the conversion:

Http://jingyan.baidu.com/article/495ba84109665338b30ede98.html

Http://www.cnblogs.com/syqlp/p/6586995.html

http://blog.csdn.net/xy2204/article/details/50522075

Binary fast-forward decimal method:

Show in 8-bit:

1. The first type:

00000001 1

00000010 2

00000100 4

00001000 8

00010000 16

00100000 32

01000000 64

10000000 128

2. The second type:

00000001 1

00000011 3

00000111 7

00001111 15

00011111 31

00111111 63

01111111 127

3. The third type:

10000000 128

11000000 192

11100000 224

11110000 240

11111000 248

11111100 252

11111110 254

As an example: 11101011

Can be divided into:

11100000 (third type above) 224

00001000 (first type above) 8

00000011 (second type above) 3

We do this by remembering the above three types of conversions, and then adding (addition mental arithmetic you will) get results immediately: 235

==================================================================================

Method Two:

Memorize the following arrangement, in fact, very easy, from right to left, followed by the previous number twice times:

256 128 64 32 16 8 4 2 1

Write a random number like 48.

48 = 32 + 16, so the 32 and 16 locations are 1, the rest is 0,

Turning 2 into a binary is

256 128 64 32 16 8 4 2 1

0 0 0 1 1 0 0 0 0

Binary to decimal is much simpler,

Like a bunch of random writing 01111101.

Write First: 0 1 1 1 1 1 0 1

Then fill 128 64 32 16 8 4 2 1

Decimal is 64+32+16+8+4+1=125

Can not understand only to see the video, this way to listen to the good learning, with the text of this kind to you said, you did not point the basis, I can not let you understand!

---restore content ends---

Java Basic notes (3) binary and binary conversion

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.