


I secretly looked at some computer basics, and from now on learning Java is like cheating!
Jul 26, 2023 pm 05:30 PMBefore learning Java, I would like to ask a question. Do you think it is necessary to learn computer basics?
Many people think that there is no need to read those boring and obscure basic knowledge. It is better to start directly from HelloWorld. First touch the program, get an impression, and the code will run, and then gradually learn the syntax of the program in depth, and finally use it. Program building projects, that is, practical learning methods.
First of all, I do not deny this way of learning. It is indeed more suitable for some students, especially those who are anxious to find a job. Learn how to use it first. As for the principle, you can slowly learn it later. Dig deeper, after all, nothing is more important than bread?
But for our students who are learning logarithms from scratch, I still recommend starting with some basic knowledge of computers to understand the ideas and common sense of programming, which will also be very helpful for our future study. It's like building a house. Some people build thatched houses, some build mud houses, and some people want to build a two-story Western-style house. The depth of the foundation directly determines the level of future achievements.
So now let’s briefly understand some basic knowledge of computers.
1. Classification of machine language
Machine language
Machine language is a language that a computer can directly recognize. It is a computer language expressed directly in binary code instructions. It is a code composed of a string of 0s and 1s, with a certain number of digits, and is divided into several segments. The coding of each segment represents a different meaning. For example, the following is a simple string of machine codes:
010100100000 // 520
So many people ask, why is the machine code composed of 0 and 1?
Because the machine code needs to control the computer hardware to respond to the program instructions, 0 represents low potential, 1 represents high potential, so that a logic circuit can be generated, which is equivalent to controlling a switch. 0 is closed and 1 is open. .
Assembly language
Assembly language is a language for developers. Since the machine language is all 0 and 1, it is difficult for developers to directly control and use it, so Some special symbols need to be used as markers for binary code. Developers input these special symbols to complete the issuance of instructions and let the computer work for us. These special symbols are assembly language. Computers cannot directly recognize assembly language, and a software is required to translate assembly language into machine language. The difference between it and machine language lies in the representation method of instructions. The main body of assembly language is assembly instructions. Compared with machine instructions, programmers are easier to remember.
MOV AX,1234H //匯編指令: 寄存器AX的內(nèi)容送到1234H中 101110000011010000010010 //機器指令
High-level language
High-level languages ??are common such as: c, c, java, python, php, etc.
It is closer to our normal thinking. Its biggest feature is that it is easy to write and the code is readable. To achieve the same function, it takes less time to use high-level languages, the program code is shorter, and it is easier to read. Second, high-level languages ??are portable, that is, a piece of code can be run on different types of computers with little or no modification.
print('Hello World') // python版HelloWorld
我們從這個程序可以看出來,高級語言屏蔽了機器內(nèi)部指令運行細節(jié),我們可以像寫作一樣書寫程序,而不用關(guān)心語言內(nèi)部的實現(xiàn)細節(jié),這大大提高了我們的開發(fā)效率,節(jié)約開發(fā)成本。
當然,其缺點也很明顯,使用高級語言編寫的程序運行時,需要先將其翻譯成低級語言計算機才能運行它,在翻譯過程中可能會產(chǎn)生一些多余的部分,運行效率低些。另外,對硬件的可控性相對于低級語言弱些,目標代碼量較大。
二. 進制
推薦使用在線工具進行進制轉(zhuǎn)換:
https://tool.oschina.net/hexconvert/
二進制
由數(shù)字0和1組成,逢二進一,比如機器碼就是二進制的,是最簡單的計算機可讀懂的代碼,例如 0101
(表示十進制數(shù)字5)。
八進制
由1到7組成的數(shù)字串,數(shù)字最大不會超過7,逢八進一,例如 157
(表示十進制數(shù)字111)
十進制
我們?nèi)粘J褂玫臄?shù)字都是十進制類型的,逢十進一,例如 0123456789。
十六進制
由1到9,a-f(或者是A-F,分別代表10-15)組成的數(shù)字串,數(shù)字最大不會超過15,其中字母是不區(qū)分大小寫的,逢十六進一,例如0F83
(表示十進制數(shù)3971)
進制轉(zhuǎn)換
1. K進制與十進制數(shù)的轉(zhuǎn)換
假設(shè)有一個n+1位的K進制數(shù),它的形式如下:
AnAn-1…A3A2A1A0
則它的大小為:(也就是對應(yīng)的我們能看懂的十進制數(shù)為)
A0 * K^0 + A1 * K^1....+ An * K^n //K^n表示K的n次方
二進制數(shù):10101 轉(zhuǎn)換成 十進制數(shù)為:21
1*2^4 + 0*2^3 + 1*2^2 + 0*2^1+1*2^0 = 21
2. 十進制與k進制的轉(zhuǎn)換
短除法。
舉個栗子:

從圖可以看出,用十進制數(shù)21一直除以2,每次得到的余數(shù)倒數(shù)就是最后的二進制數(shù)10101。同樣,十進制轉(zhuǎn)八進制、十進制轉(zhuǎn)十六進制都是一樣的套路,非常簡單。
3. 二進制與八進制和十六進制之間轉(zhuǎn)換
8是2的3次方,16是2的4次方,所以這之間的轉(zhuǎn)換存在一種快捷方法。以2轉(zhuǎn)8示例,將2進制從低位到高位,每3個一組,如果是十六進制就每4個一組,高位不足3位的補0,然后將每組依次轉(zhuǎn)換成對應(yīng)的十進制,得到的結(jié)果就是對應(yīng)的8進制或者16進制。
二進制10101100101轉(zhuǎn)八進制:2545

二進制10101100101轉(zhuǎn)十六進制:565

三. 原碼、反碼、補碼
在計算機中,最小的單位是位,也稱為比特(bit)。而另一個常用單位是字節(jié),一個字節(jié)是8位,也就是8比特,所以我們常用的二進制表示法是8位。
原碼
原碼是一種非常常見的二進制表示形式。在原碼中,為了區(qū)別正數(shù)和負數(shù),將二進制中的最高位作為符號位,如果是0表示正數(shù),如果是1表示負數(shù)。
舉個栗子:
0000 0001 // 表示 1 1000 0001 // 表示 -1
反碼
不知道大家有沒有注意到原碼的一個問題,那就是負數(shù)參與計算的時候,比如

出現(xiàn)了一個大問題,就是1 + (-1) 不等于0,而等于 -2。
這可咋整?
In order to solve this problem, smart computer predecessors thought of reverse coding. The rules for converting original code to inverse code are: The inverse code of a positive number is itself, the inverse code of a negative number is that the sign bit remains unchanged, and other bits are inverted. The rule of negation is that if it is 0, it becomes 1, and if it is 1, it becomes 0.
Let’s take a look at the calculation of converting to the inverse code:

The result obtained is 1111 1111.
Hey? This is wrong, why is it not 0?
Don’t worry, this is just the calculation result of the inverse code. We convert the inverse code into the original code 1111 1111 —> 1000 0000, and get -0, which is 0, which is completely in line with the expected result and solved. Calculation problem of original code.
Complement code
The complement code solves the problem of negative number calculation, but there is still one problem that has not been solved, which is -0. Due to the existence of the sign bit of the highest bit of a negative number, the original eight-bit binary number can represent 2 to the 8th power, that is, 256 numbers. However, using the original code and the complement code can only represent 255, which is very uncomfortable for us. , so how can we make up for this missing number?
The bald programmers also came up with the corresponding solution - code complement.
Rules for converting original code to complement code: The complement code of a positive number is itself, the complement code of a negative number is that the sign bit remains unchanged, and the remaining digits are inverted (that is, they become the complement code) and then added 1.
For example:
Original code: 0000 0001, complement code: 0000 0001
Original code: 1000 0001, complement code: 1111 1111
Calculate:

#As can be seen from the above, using complement calculation we get 0 (instead of -0), which solves the problem of one less number.
In the complement code, it is specified that 0 is represented as 0000 0000, and 1000 0000 is represented as -128. Note that this is a rule.
Notes
One's complement and one's complement cannot be directly used to convert binary to decimal. To get the corresponding size into the corresponding decimal system, you should first convert it into the original code. In other words, the original code is a form of expression that is directly related to the size
In computer systems, values ????are always represented and stored in the form of complement numbers
The original code, complement and complement of positive numbers are the same
The original code of negative numbers is inverted: the sign bit remains unchanged, and the remaining bits are inverted.
Negative numbers are converted to complement: the sign bit remains unchanged, and the remaining bits are inverted and then plus one
Negative numbers are complemented to complement: the sign bit remains unchanged , the remaining bits are reduced by one
The negative number is converted to the original: the sign bit remains unchanged, the remaining bits are reduced by one and then inverted
The above is the detailed content of I secretly looked at some computer basics, and from now on learning Java is like cheating!. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

The settings.json file is located in the user-level or workspace-level path and is used to customize VSCode settings. 1. User-level path: Windows is C:\Users\\AppData\Roaming\Code\User\settings.json, macOS is /Users//Library/ApplicationSupport/Code/User/settings.json, Linux is /home//.config/Code/User/settings.json; 2. Workspace-level path: .vscode/settings in the project root directory

To correctly handle JDBC transactions, you must first turn off the automatic commit mode, then perform multiple operations, and finally commit or rollback according to the results; 1. Call conn.setAutoCommit(false) to start the transaction; 2. Execute multiple SQL operations, such as INSERT and UPDATE; 3. Call conn.commit() if all operations are successful, and call conn.rollback() if an exception occurs to ensure data consistency; at the same time, try-with-resources should be used to manage resources, properly handle exceptions and close connections to avoid connection leakage; in addition, it is recommended to use connection pools and set save points to achieve partial rollback, and keep transactions as short as possible to improve performance.

DependencyInjection(DI)isadesignpatternwhereobjectsreceivedependenciesexternally,promotingloosecouplingandeasiertestingthroughconstructor,setter,orfieldinjection.2.SpringFrameworkusesannotationslike@Component,@Service,and@AutowiredwithJava-basedconfi

itertools.combinations is used to generate all non-repetitive combinations (order irrelevant) that selects a specified number of elements from the iterable object. Its usage includes: 1. Select 2 element combinations from the list, such as ('A','B'), ('A','C'), etc., to avoid repeated order; 2. Take 3 character combinations of strings, such as "abc" and "abd", which are suitable for subsequence generation; 3. Find the combinations where the sum of two numbers is equal to the target value, such as 1 5=6, simplify the double loop logic; the difference between combinations and arrangement lies in whether the order is important, combinations regard AB and BA as the same, while permutations are regarded as different;

java.lang.OutOfMemoryError: Javaheapspace indicates insufficient heap memory, and needs to check the processing of large objects, memory leaks and heap settings, and locate and optimize the code through the heap dump analysis tool; 2. Metaspace errors are common in dynamic class generation or hot deployment due to excessive class metadata, and MaxMetaspaceSize should be restricted and class loading should be optimized; 3. Unabletocreatenewnativethread due to exhausting system thread resources, it is necessary to check the number of threads, use thread pools, and adjust the stack size; 4. GCoverheadlimitexceeded means that GC is frequent but has less recycling, and GC logs should be analyzed and optimized.

fixture is a function used to provide preset environment or data for tests. 1. Use the @pytest.fixture decorator to define fixture; 2. Inject fixture in parameter form in the test function; 3. Execute setup before yield, and then teardown; 4. Control scope through scope parameters, such as function, module, etc.; 5. Place the shared fixture in conftest.py to achieve cross-file sharing, thereby improving the maintainability and reusability of tests.

TheJVMenablesJava’s"writeonce,runanywhere"capabilitybyexecutingbytecodethroughfourmaincomponents:1.TheClassLoaderSubsystemloads,links,andinitializes.classfilesusingbootstrap,extension,andapplicationclassloaders,ensuringsecureandlazyclassloa

Use classes in the java.time package to replace the old Date and Calendar classes; 2. Get the current date and time through LocalDate, LocalDateTime and LocalTime; 3. Create a specific date and time using the of() method; 4. Use the plus/minus method to immutably increase and decrease the time; 5. Use ZonedDateTime and ZoneId to process the time zone; 6. Format and parse date strings through DateTimeFormatter; 7. Use Instant to be compatible with the old date types when necessary; date processing in modern Java should give priority to using java.timeAPI, which provides clear, immutable and linear
