当前位置:网站首页>Byte order, object class
Byte order, object class
2022-06-10 04:31:00 【little-peter】
- Java The byte order of the integer is ?
answer :Big-Endian( Big end )
Byte order refers to the storage order of each byte when multi byte data is stored in the computer memory or transmitted through the network . Usually there are Little-Endian( The small end ) and Big-Endian( Big end ) Two ways . These two methods will be introduced respectively .
(1)Little-Endian
Little-Endian( The small end ) It means that the low order bytes are stored in the low address end of the memory , The high bits are stored in the high address of memory .
for example , When stored in small end mode , Hexadecimal digits represent 0x12 34 56 78 The storage mode in memory is :
Low address ---------------------------------------> High address
0x78 | 0x56 |0x34 |0x12
(2)Big-Endian
Big-Endian( Big end )
A little ( Opposite to the small end , I won't go into details here )
Why should we distinguish between small and large ends ?
Because in the computer system , All storage is stored in bytes , But in most programming languages , Except for one byte char Out of data type , There are other data types that take up more than one byte . for example , stay Java In language ,short Type takes two bytes ,int Type account 4 Bytes . So how to store these data that occupy multiple bytes ? You can use the big end to store , You can also use the small end to store . Different programming languages , Different processors may use different storage methods .
So how do you know Java The byte order of the language ?
You can know by looking at how byte arrays are stored in memory , The sample code is as follows :
import java.io.ByteArrayInputStream;
import java.io.DataInputStream;
import java.io.IOException;
public class T {
public static void main(String[] args) throws IOException {
byte[]arr=new byte[4];
arr[0]=0x78;
arr[1]=0x56;
arr[2]=0x34;
arr[3]=0x12;
ByteArrayInputStream bais=new ByteArrayInputStream(arr);
DataInputStream dis=new DataInputStream(bais);
System.out.println(Integer.toHexString(dis.readInt()));
}
}
The running result of the program is :

From the above running results, we can see that , High byte (78) Stored in low address , It's obviously big end .
although Java The big end is used , In some cases it may also be necessary to obtain CPU Big end or small end ,Java Provides a class library that can be used to get CPU Big end or small end :
java.nio.ByteOrder.*- Object class
object Class method
Method name Return type Methods described clone() Object Create and return a copy of an object equals(Object obj) boolean Judge obj Whether the object is equal to this object finalize() void When the garbage collector determines that there are no more references to the object , This method is called by the object's garbage collector getClass() Class<?> return Object Runtime class for hashCode() int Returns the hash code value of the object notify() void Wake up a single thread waiting on this object monitor notifyAll() void Wakes up all threads waiting on this object monitor toString() String Returns the string representation of the object wait() void This object is called in another thread notify() Method or notifyAll() Before the method , Make the current thread wait wait(long timeout) void This object is called in another thread notify() Method or notifyAll() Before the method , Or before the specified amount of time , Make the current thread wait wait(long timeout,int nanos) void This object is called in another thread notify() Method or notifyAll() Before the method , Or some other thread breaks the current thread , Or has exceeded a certain actual amount of time before , Make the current thread waitObject Class is the root of class hierarchy , stay Java In language , All classes basically inherit from this class . and Object Class is Java The only class in a language that does not have a parent class , And all the other classes , Including standard containers , For example, an array of , Inherit from Object class .
- Math.round(12.5) The return value of is equal to ?Math.round(-12.5) The return value of is equal to ?
answer :13,-12
Math Class mainly provides the following 5 Methods related to rounding :
1)static double ceil(double a): Return greater than or equal to a Minimum integer of
2)static double floor(double a): Return less than or equal to a Maximum integer for
3)static double rint(double a): The rounding method , Return and a The nearest integer to the value of , by double type
4)static long round(double a): The rounding method , Return and a The nearest long integer to the value of
5)static int rount(float a): The rounding method , Return and a The closest integer to the value of
For this problem ,round Is a rounding method ,12.5 The decimal part of is 0.5, When executed Math.round() In operation , Results need to be entered , So the result is 13;-12.5 The decimal part of is also 0.5, When executed Math.round() In operation , The result also needs to enter ,-12>-13, therefore , The result is rounded up to -12.
边栏推荐
- [understanding of opportunity -20]: Guiguzi - Manoeuvring chapter - one opening and one closing, one movement and one relaxation are called manoeuvring, which can be used in the workplace.
- [in depth study of 4g/5g/6g topic -26]: 5g NR startup process 4.4 - scheduling of RRC connection response message msg4 (rrcsetup authorization) and detailed explanation of message content
- Jenkinsclient | easy to use Jenkins client
- [in depth study of 4g/5g/6g topic -27]: 5g NR startup process 4.5 - RRC connection response message msg4, first scheduling of PUCCH uplink control channel, UCI and HARQ response
- How to write OKR for test engineers to improve quality?
- midway的使用教程
- 测试工程师提高质量的OKR该如何写?
- 超好用的 Chrome 插件!
- Crack the five myths of programmers, and new programmer 004 is officially launched!
- APISpace 分钟级降水预报API接口 免费好用
猜你喜欢

什么时候用@ComponentScan?与@MapperScan有什么区别?
![[science and technology specialty-1]: overview and advantages of science and Technology Specialty Students](/img/f6/77fda73053ed4afefc8277e196c1a9.png)
[science and technology specialty-1]: overview and advantages of science and Technology Specialty Students

Celery | 任务队列神器

Final examination paper 2 of the first postgraduate course in Dialectics of nature

图解固件、驱动、软件的区别
![[机缘参悟-16]:金字塔层次结构符合天道自然](/img/d3/799e67b6dc825758927191d2ef8c4f.jpg)
[机缘参悟-16]:金字塔层次结构符合天道自然
![[joint search set] sympodial plants (number of connected blocks)](/img/47/0dd7c64568a2176640dcab835228c6.png)
[joint search set] sympodial plants (number of connected blocks)

How to write Scala code in idea

These programming languages are old and almost dead. Young people can't touch them

When to use @componentscan? What is the difference with @mapperscan?
随机推荐
Celery | 任务队列神器
FastApi-16-页面美化-1
Source code encryption software type analysis
How to view Scala source code in idea
CSDN audio and video technology developers' online survey
测试工程师提高质量的OKR该如何写?
mindconvert模型转换中clip算子报错
Gevent | 异步就用它!
libc、glibc和glib的关系
[机缘参悟-16]:金字塔层次结构符合天道自然
Fastapi-17-page beautification-2
Pampy | 超强的模式匹配工具
APISpace 日出日落API接口 免费好用
idea中怎樣編寫Scala代碼
Getting started with JDBC example
90. 闭锁
Jmeter测试TCP百万连接
这些编程语言老了,差不多死透了,年轻人不能碰
[Error] anonymous type with no linkage used to declare function ‘bool InitSLinkList
Using VBA's WebBrowser control to realize single sign on (SSO) in Excel