Comments (4)
因为存在二进制补码问题
from mysql-protocol.
是的,的确存在二进制补码的问题。但是这个问题应该是发生在低位转高位的时候。
下面将byte转为long的时候,考虑到补码的问题,所以需要&0xff。
public long readUB4() {
final byte[] b = this.data;
long l = (long) (b[position++] & 0xff);
l |= (long) (b[position++] & 0xff) << 8;
l |= (long) (b[position++] & 0xff) << 16;
l |= (long) (b[position++] & 0xff) << 24;
return l;
}
但是像下面这样的高位转低位也存在补码的问题吗?
public static final void writeUB3(ByteBuffer buffer, int i) {
buffer.put((byte) (i & 0xff));
buffer.put((byte) (i >>> 8));
buffer.put((byte) (i >>> 16));
}
from mysql-protocol.
你好,你说的是高到低没有问题的,此时写上0xff就是看着明确点
from mysql-protocol.
好的,谢谢你的解答
from mysql-protocol.
Related Issues (6)
- ResultsetPacket有提供吗? HOT 1
- 还有RowDataPacket HOT 2
- BufferUtil相关类疑惑 HOT 2
- 这是从cobar里提出来的吗 HOT 1
- 请问我现在捕获到了mysql的通讯数据包,mysql-protocl怎么用 HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mysql-protocol.