Skip to content

Instantly share code, notes, and snippets.

@MangoLiu
Last active December 30, 2015 08:09
Show Gist options
  • Save MangoLiu/7801008 to your computer and use it in GitHub Desktop.
Save MangoLiu/7801008 to your computer and use it in GitHub Desktop.
byte ----> 8 bits(输出byte表示的8位bit串)
public static String byte2bits(byte b) {
int z = b;
z |= 256; //使最后能截取到8位,而又不影响byte的原来值。
String str = Integer.toBinaryString(z);
int len = str.length();
return str.substring(len - 8, len);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment