-
Notifications
You must be signed in to change notification settings - Fork 62
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add more methods to convert primitive type to byte array #1149
Add more methods to convert primitive type to byte array #1149
Conversation
public static byte[] toBytes(long value) { | ||
byte[] result = new byte[8]; | ||
for (int i = 0; i < 8; i++) { | ||
result[i] = (byte) ((value >> (7 - i) * 8) & 0xff); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
直接列舉不要用 for loop,這樣效能會比較好
}; | ||
} | ||
|
||
public static byte[] toBytes(Boolean value) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
boolean
}; | ||
} | ||
|
||
public static byte[] toBytes(Double value) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
double
#1140
有些 read 在 #1145 有變更,這邊就先暫時沒有變動