Java Binary Encode toBin(long value, int width)

Here you can find the source of toBin(long value, int width)

Description

to Bin

License

Open Source License

Declaration

public static String toBin(long value, int width) 

Method Source Code

//package com.java2s;

public class Main {
    public static String toBin(long value, int width) {
        char[] result = new char[width];

        for (int cntr = 0; cntr < width; cntr++)
            result[width - cntr - 1] = (value & (0x1 << cntr)) == 0 ? '0' : '1';

        return new String(result);
    }/*  w  ww  .j  a  v  a 2  s . co m*/
}

Related

  1. toBin(byte n)
  2. toBin(int bin, int size)
  3. toBin(int size, String bitString)
  4. toBin(int x)
  5. toBinArray(String hexStr)
  6. toBinary(byte b)
  7. toBinary(byte b)
  8. toBinary(byte b)