The next day basic grammar learning

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

Next day Notes

    1. Key words

A Words that are given special meaning in Java: Each keyword has its own specific meaning and is defined by Java.

B All made up of lowercase letters

2. Identifiers

A The content that you define in Java, called an identifier

B Naming rules for identifiers:

1) identifiers consist of number 0-9, letter a-z,a-z, underscore _, dollar sign $

2) numbers cannot begin

3) cannot be a keyword

C Naming rules for identifiers (hump naming method)

1) class name: The first letter is required, the following letter is lowercase, the second word is capitalized in the first letter

Example: Jinyanlong person

2) Method Name: Requires first letter lowercase, second word capitalized

Distance: Beijingshi

3) Name of variable: all lowercase

4) The name of the constant: all caps

3. Constants

A Constants are fixed content in the program

B Classification of constants

1) integer constant: all integers 123 0-12

2) Decimal constant: 1.1 2.2 3.3

3) Character constants: the use of single quotation marks, called character constant ", character constants can only have one character.

Note: "Can be a space, but not Shen Nong also do not write

4) String constants: used in double quotation marks, called string constants, string constants do not limit the number of characters.

5) Boolean constant: Only two values, true and false. are all keywords.

True: The condition is true.

False: Condition fails, indicates false

6) NULL constant: Only one content null is also a keyword, followed by a reference data type that explains

4. Binary

A The binary is the way that people use to count, decimal every ten in a

1) Binary: Every second into 10 1

2) Octal: Every eight into a 0-7

3) Decimal: Every ten into a 0-9

4) 16 binary: Every 16 in a 0-9 a B C D E F

B The origin of the binary

The earliest computer, electrical signal (switch)

Then the numbers, the switches that indicate the electrical signals, are only 0 and 1.

8 binary bits represent 1 bytes byte a 8 bit

1024 bytes = 1000 bytes KB

Because the digits of the binary are too long and the memory is not good

3 binary represents the birth of 1-bit maximum value 78 binary

4 binary represents the birth of 1-bit maximum F 16 binary

In-process

C. Code implementation:

Results:

5. Binary conversion

A. Decimal turns into binary

Conversion method: Divide by cardinality, get remainder except 2 get remainder

62 binary is 110

72 binary is 111

152 binary is 1111

B. Binary into decimal

Conversion method: Each binary digit, multiplied by the power of 2, with 1 bits of data added

1001101 starting from the lowest bit, multiplying each bit by the power of 2

C. Binary into octal

Convert three binary to a group, 3-bit binary to decimal

110011001

D. Eight binary into binary

Each bit of octal, turn into binary, less than three bits of the complement 0

125

E. Binary into hexadecimal

Convert four binary to a group, turn to decimal

1100011100101

F. 16 binary into binary

Convert each bit in hex to binary, less than 4 bit 0

23d4

G. 16 binary, octal, turn into binary, in turn into decimal

Binary conversion

6. Using the 8421 fast conversion method

32 16 8 4 2 1

56 1 1 1 0 0 0

Ask: 8 bits are 10 binary is a few

11111111 255

7 bits are 10 binary is a few

1111111 127

16 binary bits are 10 binary is a few

65535

Remember three numbers 255 127 65535, later data types are related

7. Original code anti-code complement

Binary representation of an integer, code

The human eye sees the data, all is the decimal, all is the original code

The underlying operation of a computer is to use the complement operation

A positive representation of 1 bytes

1 10000001

Positive and negative numbers for the calculation, the highest bit of the number is what, if it is 0, positive, if it is 1 negative

Positive 1:

Original code: Symbol bit value bit

0 0000001

Anti-code: 0 0000001

Complement: 0 0000001

Conclusion the original, inverse and complement of positive numbers are consistent.

Negative 1:

Sign bit value bit

Source: 1 0000001

Anti-code: 1 1111110

Complement: 1 1111111

Conclusion: Negative original sign bit is 1, value bit is converted to binary

Negative counter sign bit unchanged, value bit inverse 1 Change 0 0 to 1

Negative complement sign bit invariant, inverse code value bit +1

-1 10000001 11111110 11111111

Summary: Positive is the same as the original, negative number is reversed +1 symbol unchanged

Small exercise:

It is known that the original code of a number x is 0b10110100, and tries to find the complement and inverse code of x.

A number of X's complement 0b11101110 is known, try to find its original code.

10110100 is a source code that calculates the inverse code and the complement

Original code: Symbol bit value bit

1 0110100

Anti-code: 1 1001011

Complement: 1 1001100

11101110 is a complement, calculating the inverse code and the original code

Complement: Symbol bit value bit

1 1101110

Anti-code: 1 1101101

Original code: 1 0010010

8. Variables

Variables and constants: Constants invariant, variable values can vary

Variables actually store a value, but each time a variable is stored, the data can be changed to make it easier to calculate

In advance, variables can be understood as the unknown in mathematics

Computer, it needs to be calculated, the running program will be in the memory

To define the format of a variable: remember, remember!

Data type variable name = assigned value;

Data type: What type of data is stored in an in-memory region

Variable name (identifier): a name for the memory area

The assignment is to store the data in this area

Variable in memory

9. Data type

Java is a language that enforces data types

Data in a computer, categorized into two categories

Basic data type:

Numeric type:

Integer

byte type, short integer, integral type, long integer type

Floating point

Single-precision, double-precision

Character type: Single quotation mark

Boolean: True and False values

Reference data type

Class

Array

Interface

Integer:

Byte bytes in memory account for 1 bytes, one 8 bit, 8 bits

Range of values 1 bytes-128 ~ 127

Short-integer 2 bytes, 2 8-bit, 16 bits

Range of values 2 bytes-32768 ~ 32767

integer int in memory is 4 bytes, 4 8 is, 32 bits

All integers in Java, default to int type

Range of values 4 bytes-2147483648 ~ 2147483647

Long integer 8 bytes in memory, 8 8 bits 64 bits

Range of values 8 bytes

A byte short int long 4 are keywords that represent the integer type of the keyword

1 2 4 8

Floating point:

Single precision: float memory accounted for 4 bytes 32 x bits

Double precision: Double 8 bytes in memory 64 bits

Note: Double is the default data type for all floating-point types in Java

Float>long

Character type:

Char: Only one symbol can be saved, 2 bytes in memory 16 bits

Char type in Java, encoded in Unicode with a Chinese character occupying two bytes in memory

Boolean type:

Only two values of True and flase,1 bytes

The data type code indicates:

Results:

10. Considerations for defining and using variables

A Scope Problem of variables

The defined variable is valid only between the defined pair of curly braces, and it is invalid to go out.

B Defines a variable that must be assigned a value that is not assigned

C. It is recommended to define 1 variables on one line of code

11 Conversions between data types

A. Boolean types cannot be converted to other data types

B. Default Conversion

Byte,short,char-int-long-float-double

Default conversion

C. Automatic conversion in operations

In Java, the data that is calculated must be the same data type

If the data types are different, type conversions occur, with the principle that small data types are converted to large data types (where size refers to the range of values, the number of bytes).

1) Automatic conversion: Do not need program personnel participation, conversion principle:

If there is a double type in the calculation, the result must be a double type. Example: 1+3-1+1.1+5

If there is a flaot type in the calculation, there is no double type, the result is a float type

If there is no floating point in the calculation, if there is a long type, the result is a long type

Code Demo:

Graphic interpretation

2) Cast: Large range of values, turn into a small range of values

Must be manually engaged by the program personnel, the JVM does not perform strong

Manual to standard format: target type variable = (target type) converted Data

Code Demo One:

Results:

Code Demo 2:

Graphic interpretation

Code Demo 3:

Results:

12. Arithmetic of numbers and characters, strings

System.out.println (' a ');

System.out.println (' a ' + 1); 98

System.out.println ("Hello" + ' a ' + 1); Helloa1

Any data type and "" string do the + operation, the result is a string

"" + any type

In the string + is not an addition operation, the join symbol

Code Demo:

Results:

ASCII encoding table

US Standard Information Interchange code

Can the computer directly recognize human language?

A-Z 0-9 symbol

So, since the computer recognizes the 01 binary

Let the life of a text, corresponding to 1 decimal numbers, the computer to go to the binary

Provisions:

A 97

B 98

The next day basic grammar learning

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.