当前位置:网站首页>Type conversion basis
Type conversion basis
2022-06-25 21:22:00 【vancomycin】
Automatic type conversion :
1. The two types are compatible
2. The target type is greater than the original converted type It's like filling a small cup with water and pouring it into a large one
short s = 123;
int i = s; int The value range of is relative to short Much bigger , So when you convert a type, you automatically convert it
2. Cast
1. The two types are compatible 1. The target type is smaller than the converted type Pour the water in the big cup into the small one If it is full, the water will overflow
short s = 123;
byte b = (byte)s; Bold font Cast No error will be reported during compilation But the result of compilation may not be correct
3. Cast
The integer length is sufficient , Data integrity . example :int i = 100; byte b = (byte)i; //b = 100 Insufficient integer length , Data truncation . example :int i = 10000; byte b = (byte)i; //b = 16( Sign bit change , May become negative )
int It's four bytes , So we can see from the following pictures stay int When displayed in hexadecimal ( The second line of the picture is yellow ) It can be seen that
byte When it is a hexadecimal byte, you can see from the first line of the picture
When converting large data types to small data types , The first one is cut off , Only the last eight bits are calculated
The following operation 0 Is a positive number 1 It's a negative number

Decimals are forced to integers , Data truncation . example :double d = 2.5; int i = (int)d; //i = 2( The decimal places are rounded off ) Characters and integers are converted to each other , Data integrity . example :char c = 65; int i = c; //i = 65
3. Automatic type promotion
When calculating : One of the two operands is double, The calculation result is improved to double. If there is no... In the operand double, There is one for float, The calculation result is improved to float. If there is no... In the operand float, There is one for long, The calculation result is improved to long. If there is no... In the operand long, There is one for int, The calculation result is improved to int. If there is no... In the operand int, Are all short or byte, The calculation result is still improved to int.
special : Any type and String Add up (+) when , It's actually splicing , The result is automatically promoted to String.
2. Arithmetic operator Operate on two operands
| + | Add 、 Sum up |
|---|---|
| - | reduce 、 Subtraction |
| * | ride 、 quadrature |
| / | except 、 Seeking quotient |
| % | model 、 Seeking remainder |
The arithmetic operator is right Simple addition, subtraction, multiplication, division and remainder of data
| ++ | Increasing , A variable's value +1 |
|---|---|
| - - | Decline , A variable's value -1 |
a++ a Self increasing of
a++ Express a = a+1
a++ ++ before ++ It's different to do the operation after
If you output a single statement, there is no problem
If it's not a separate statement
a++ First perform other operations before proceeding ++ operation
++a Progressiveness self increasing operation Doing other operations
a-- a Self subtraction of
a-- = a-1
Before means before ++ perhaps -- Then perform other
After means to execute other first Re execution ++ perhaps --
3. Assignment operator
1.
= assignment += Assignment after summation -= Assign value after difference *= Assign value after quadrature /= Assignment after division %= Assign a value after taking the remainder There is only one thing to note Every time the assignment operator takes the remainder after addition, subtraction, multiplication, division, etc In assignment
4. Relational operator
1.
> Greater than < Less than >= Greater than or equal to <= Less than or equal to == be equal to != It's not equal to Only one thing to be sure of is The result of each relational operator is boolea type The results are True or false
5. Logical operators
1
Logical operators Two boolea Logical comparison of operands or expressions of type
&& And ( also ) Two operands , It's true at the same time , The result is true || or ( perhaps ) Two operands , One is true , The result is true ! Not ( Take the opposite ) Meaning for “ No ”, True is false , False is true
Ternary operator Assign the result of the judgment to the variable
summary :
Variable : A piece of storage space in computer memory , Is the basic unit for storing data . data type : Basic data type (8 Kind of )、 Reference data type (String、 Array 、 object ). Operator : Arithmetic operator 、 Assignment operator 、 Relational operator 、 Logical operators . Type conversion : Automatic type conversion 、 Cast . Type promotion : Regular type promotion between numbers , Special type promotion of characters . Console entry : Introduce the toolkit 、 Statement Scanner、 Call the corresponding function to receive the console input data .
边栏推荐
- Svn various color states
- What is DNS (domain name server)? (Powercert animated videos)
- lombok
- Send a more awesome website, which can convert curl commands into code in any language
- js (1)
- Finger collar pin exclusive Medal
- Desktop network error display red ×, Component failed to start
- Nmap is simple and practical
- 1.1-mq visual client preliminary practice
- The correct way to clear the cache of the computer. The computer will not get stuck immediately after changing. practical
猜你喜欢
![[nailing scenario capability package] smart office phone](/img/ec/c2f342a54ab69d8b834a8a1c8f8a01.jpg)
[nailing scenario capability package] smart office phone

Installing mysql8 under centos8

A simple file searcher

Finger collar pin exclusive Medal

Flexible scale out: from file system to distributed file system
![[nailing scenario capability package] video conference (official conference system)](/img/ec/c2f342a54ab69d8b834a8a1c8f8a01.jpg)
[nailing scenario capability package] video conference (official conference system)

UDP Vs TCP (Powercert animated videos)

Using two stacks to realize the function of one queue?

js (1)

Renren mall locates the file according to the route
随机推荐
Nine built-in objects of JSP and four scopes of Servlet
Illustrated with pictures and texts, 700 pages of machine learning notes are popular! Worth learning
银河证券靠谱吗?开证券账户安全吗?
Yolov4 reading notes (with mind map)! YOLOv4: Optimal Speed and Accuracy of Object Detection
Yolov4 improved version comes out! Yolov4 extended edition! Yolov4 launched scaled-yolov4: scaling cross stage partial network
How to buy the millions of medical insurance for children? How much is it a year? Which product is the best?
js(3)
XMIND to excel test case
Patrol script
Working principle and experimental analysis of DHCP
Jmeter- (III) create user test cases for interface testing
Php7.4 arm environment compilation and installation error invalid 'ASM': invalid operate prefix '%c'
Data query of server SQL. The most important chapter in database learning
Unable to connect to the server remotely locally using the Jupiter notebook
Jingxi Pinpin wechat applet -signstr parameter encryption
[nailing scenario capability package] exhibition admission
[nailing scenario capability package] video conference (official conference system)
Getting started and using postman
Those high-frequency and real software test interview questions sorted out by the test director in 7 days, come to get
[machine learning] machine learning from zero to mastery -- teach you to understand the principle of decision tree