/**
 * Convert the byte into binary form of string.
 * @param b
 * @return
 */
public static String convertByteToBinary(byte b) {
	StringBuilder result = new StringBuilder();
	for (int i = 0; i < 8; i++) {
		if (((b >> (7 - i)) & 0x1) == 1) {
			result.append(1);
		} else {
			result.append(0);
		}
	}
	return result.toString();
}


Back to JavaHowTo

Alumni Liaison

Prof. Math. Ohio State and Associate Dean
Outstanding Alumnus Purdue Math 2008

Jeff McNeal