Skip to content
Navigation Menu
Sign in
Appearance settings
Platform
AI CODE CREATION
GitHub Copilot
Write better code with AI
GitHub Copilot app
Direct agents from issue to merge
MCP Registry
Integrate external tools
DEVELOPER WORKFLOWS
Actions
Automate any workflow
Codespaces
Instant dev environments
Issues
Plan and track work
Code Review
Manage code changes
Code Quality
Enforce quality at merge
APPLICATION SECURITY
GitHub Advanced Security
Find and fix vulnerabilities
Code security
Secure your code as you build
Secret protection
Stop leaks before they start
EXPLORE
Why GitHub
Documentation
Blog
Changelog
Marketplace
View all features
Solutions
BY COMPANY SIZE
Enterprises
Small and medium teams
Startups
Nonprofits
BY USE CASE
App Modernization
DevSecOps
DevOps
CI/CD
View all use cases
BY INDUSTRY
Healthcare
Financial services
Manufacturing
Government
See all industries
View all solutions
Resources
EXPLORE BY TOPIC
AI
Software Development
DevOps
Security
View all topics
EXPLORE BY TYPE
Customer stories
Events & webinars
Ebooks & reports
Business insights
GitHub Skills
SUPPORT & SERVICES
Documentation
Customer support
Community forum
Trust center
Partners
View all resources
Open Source
COMMUNITY
GitHub Sponsors
Fund open source developers
PROGRAMS
Security Lab
Maintainer Community
GitHub Stars
Archive Program
REPOSITORIES
Topics
Trending
Collections
Enterprise
ENTERPRISE SOLUTIONS
Enterprise platform
AI-powered developer platform
AVAILABLE ADD-ONS
GitHub Advanced Security
Enterprise-grade security features
Copilot for Business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Pricing
Search
/
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
SuperDCode
toBeTopJavaer
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
More
items
Files
Expand file tree
master
Breadcrumbs
toBeTopJavaer
/
basics
/
java-basic
/
big-endian-vs-little-endian.md
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
17 lines (10 loc) · 1.52 KB
master
Breadcrumbs
toBeTopJavaer
/
basics
/
java-basic
/
big-endian-vs-little-endian.md
Copy path
Top
File metadata and controls
Code
Blame
17 lines (10 loc) · 1.52 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
字节序
,
也就是字节的顺序
,
指的是多字节的数据在内存中的存放顺序
。
在几乎所有的机器上
,
多字节对象都被存储为连续的字节序列
。
例如
:
如果C
/
C
++
中的一个int型变量
a
的起始地址是
&
a
=
0x100
,
那么
a
的四个字节将被存储在存储器的0x100
,
0x101
,
0x102
,
0x103
位置
。
根据整数
a
在连续的
4
byte
内存中的存储顺序
,
字节序被分为大端序
(
Big
Endian
)
与
小端序
(
Little
Endian
)
两类
。
Big
Endian
是指低地址端
存放
高位字节
。
Little
Endian
是指低地址端
存放
低位字节
。
比如数字0x12345678在两种不同字节序CPU中的存储顺序
:
Big
Endian
:
12345678
Little
Endian
:
78563412
Java采用Big
Endian来存储数据
、
C
\C++
采用Little
Endian
。
在网络传输一般采用的网络字节序是BIG
-
ENDIAN
。
和Java是一致的
。
所以在用C
/
C
++
写通信程序时
,
在发送数据前务必把整型和短整型的数据进行从主机字节序到网络字节序的转换
,
而接收数据后对于整型和短整型数据则必须实现从网络字节序到主机字节序的转换
。
如果通信的一方是JAVA程序
、
一方是C
/
C
++
程序时
,
则需要在C
/
C
++
一侧使用以上几个方法进行字节序的转换
,
而JAVA一侧
,
则不需要做任何处理
,
因为JAVA字节序与网络字节序都是BIG
-
ENDIAN
,
只要C
/
C
++
一侧能正确进行转换即可
(
发送前从主机序到网络序
,
接收时反变换
)。
如果通信的双方都是JAVA
,
则根本不用考虑字节序的问题了
。
You can’t perform that action at this time.