Skip to content
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

Merged
merged 4 commits into from
Nov 28, 2022

Conversation

Haser0305
Copy link
Collaborator

@Haser0305 Haser0305 commented Nov 21, 2022

#1140

有些 read 在 #1145 有變更,這邊就先暫時沒有變動

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);
Copy link
Contributor

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) {
Copy link
Contributor

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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

double

@chia7712 chia7712 merged commit a82f5c3 into opensource4you:main Nov 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants