Here you can find the source of toBinaryString(byte b)
public static String toBinaryString(byte b)
//package com.java2s; /******************************************************************************* * Copyright (c) 2004, 2007 Boeing./*from w w w. j a v a2 s. com*/ * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * Boeing - initial API and implementation *******************************************************************************/ public class Main { /** * NOTE the SDK supplies a Integer.toBinaryString but it is not formatted to a standard number of chars so it was not * a good option. */ public static String toBinaryString(byte b) { StringBuffer sb = new StringBuffer(); sb.append((b >> 7 & 0x01)); sb.append((b >> 6 & 0x01)); sb.append((b >> 5 & 0x01)); sb.append((b >> 4 & 0x01)); sb.append((b >> 3 & 0x01)); sb.append((b >> 2 & 0x01)); sb.append((b >> 1 & 0x01)); sb.append((b & 0x01)); return sb.toString(); } }