Conversion int to Roman numbers
from http://www.roseindia.net/java/java-tips/45examples/misc/roman/roman.shtml

@param binary the int to be converted
@return the roman number string
171269
private static String binaryToRoman(int binary)
    {
        if (binary <= 0 || binary >= 4000) 
            throw new NumberFormatException("Value outside roman numeral range.");
        String roman = ""; // Roman notation will be accumualated here.

        // Loop from biggest value to smallest, successively subtracting,
        // from the binary value while adding to the roman representation.
        for (int i = 0; i < RCODE.length; i++)
        {
            while (binary >= BVAL[i])
            {
                binary -= BVAL[i];
                roman += RCODE[i];
            }
        }
        return roman;
    }
1359712
public BEValue bdecodeNumber() throws IOException {
    int c = this.getNextIndicator();
    if (c != 'i') {
      throw new InvalidBEncodingException("Expected 'i', not '" +
              (char) c + "'");
    }
    this.indicator = 0;

    c = this.read();
    if (c == '0') {
      c = this.read();
      if (c == 'e')
        return new BEValue(BigInteger.ZERO);
      else
        throw new InvalidBEncodingException("'e' expected after zero," +
                " not '" + (char) c + "'");
    }

    // We don't support more the 255 char big integers
    char[] chars = new char[256];
    int off = 0;

    if (c == '-') {
      c = this.read();
      if (c == '0')
        throw new InvalidBEncodingException("Negative zero not allowed");
      chars[off] = '-';
      off++;
    }

    if (c < '1' || c > '9')
      throw new InvalidBEncodingException("Invalid Integer start '"
              + (char) c + "'");
    chars[off] = (char) c;
    off++;

    c = this.read();
    int i = c - '0';
    while (i >= 0 && i <= 9) {
      chars[off] = (char) c;
      off++;
      c = read();
      i = c - '0';
    }

    if (c != 'e')
      throw new InvalidBEncodingException("Integer should end with 'e'");

    String s = new String(chars, 0, off);
    return new BEValue(new BigInteger(s));
  }
557262
public static String toBinaryString(byte[] b) {
    StringBuilder s = new StringBuilder();
    for (byte by : b) {
      for (int j = 7; j >= 0; j--) {
        if ((by & (1 << j)) > 0) {
          s.append('1');
        } else {
          s.append('0');
        }
      }
      s.append(' ');
    }
    return s.toString();
  }
1088320
def _int_to_binary(integer, size=None):
    
    binary_list = map(int, format(integer, 'b'))

    if size is None:
        return binary_list
    else:
        if len(binary_list) > size:
            # Too long, take only last n
            return binary_list[len(binary_list)-size:]
        elif size > len(binary_list):
            # Too short, pad
            return [0]*(size-len(binary_list)) + binary_list
        else:
            # Just right
            return binary_list
38288
public static String byteToBits(byte b) {
        return ""
            + (byte) ((b >> 7) & 0x01) + (byte) ((b >> 6) & 0x1)
            + (byte) ((b >> 5) & 0x01) + (byte) ((b >> 4) & 0x1)
            + (byte) ((b >> 3) & 0x01) + (byte) ((b >> 2) & 0x1)
            + (byte) ((b >> 1) & 0x01) + (byte) ((b >> 0) & 0x1);
    }
432164
public String binaryToString(Object objData) 
    {
        initGlobals();
        if (objData == null)
            return Constants.BLANK;
        String string = null;
        synchronized (gNumberFormat)
        {
            if (m_ibScale != 2)
            {
                gNumberFormat.setMinimumFractionDigits(m_ibScale);
                gNumberFormat.setMaximumFractionDigits(m_ibScale);
            }
            string = gNumberFormat.format(((Double)objData).doubleValue());
            if (m_ibScale != 2)
            {
                gNumberFormat.setMinimumFractionDigits(2);
                gNumberFormat.setMaximumFractionDigits(2);
            }
        }
        return string;
    }
1317022
def int_to_roman(integer):
    
    if not isinstance(integer, int):
        raise ValueError("Input integer must be of type int")
    output = []
    while integer > 0:
        for r, i in sorted(_roman_dict.items(),
                           key=lambda x: x[1], reverse=True):
            while integer >= i:
                output.append(r)
                integer -= i
    return "".join(output)
947151
def int_to_binary(value)
      # Note: nbytes is actually an exponent.  number of bytes = 2**nbytes.
      nbytes = 0
      nbytes = 1  if value > 0xFF # 1 byte unsigned integer
      nbytes += 1 if value > 0xFFFF # 4 byte unsigned integer
      nbytes += 1 if value > 0xFFFFFFFF # 8 byte unsigned integer
      nbytes += 1 if value > 0x7FFFFFFFFFFFFFFF # 8 byte unsigned integer, stored in lower half of 16 bytes
      nbytes = 3  if value < 0 # signed integers always stored in 8 bytes

      Binary.type_bytes(0b0001, nbytes) <<
        if nbytes < 4
          [value].pack(["C", "n", "N", "q>"][nbytes])
        else # nbytes == 4
          [0,value].pack("Q>Q>")
        end
    end
899844
public void writeInt(int value) {
		try {
			buffer.writeInt(4);
			buffer.writeInt(value);
		} catch (Exception e) {
			throw new BinaryWriteFailedException(e);
		}
	}
666007
public static String toBinaryString(byte[] bytes) {
        StringBuilder buffer = new StringBuilder();
        for(byte b: bytes) {
            String bin = Integer.toBinaryString(0xFF & b);
            bin = bin.substring(0, Math.min(bin.length(), 8));

            for(int j = 0; j < 8 - bin.length(); j++) {
                buffer.append('0');
            }

            buffer.append(bin);
        }
        return buffer.toString();
    }
1033171
private static byte [] binaryIncrementPos(byte [] value, long amount) {
    long amo = amount;
    int sign = 1;
    if (amount < 0) {
      amo = -amount;
      sign = -1;
    }
    for (int i = 0; i < value.length; i++) {
      int cur = ((int) amo % 256) * sign;
      amo = (amo >> 8);
      int val = value[value.length - i - 1] & 0x0ff;
      int total = val + cur;
      if (total > 255) {
        amo += sign;
        total %= 256;
      } else if (total < 0) {
        amo -= sign;
      }
      value[value.length - i - 1] = (byte) total;
      if (amo == 0) {
        return value;
      }
    }
    return value;
  }
1167417
public static String toBinaryString(byte[] bytes, boolean isMSB) {
    StringBuilder sb = new StringBuilder();
    for (byte b : bytes) {
      String binary = String.format("%8s", Integer.toBinaryString(b & 0xFF))
          .replace(' ', '0');
      if (isMSB)
        sb.append(binary);
      else
        sb.append(new StringBuilder(binary).reverse());
    }
    return sb.toString();
  }
605424
public static byte reverseBitsInByte(final JBBPBitNumber bitNumber, final byte value) {
    final byte reversed = reverseBitsInByte(value);
    return (byte) ((reversed >>> (8 - bitNumber.getBitNumber())) & bitNumber.getMask());
  }
1170124
public static boolean[] toBinary(int number, int length)
    {
        final boolean[] binary = new boolean[length];
        for (int i = 0; i < length; i++)
        {
            binary[length - 1 - i] = (1 << i & number) != 0;
        }
        return binary;
    }
1365824
@Pure
	@SuppressWarnings("checkstyle:magicnumber")
	public static String encodeBase26(int number) {
		final StringBuilder value = new StringBuilder();
		int code = number;
		do {
			final int rest = code % 26;
			value.insert(0, (char) ('A' + rest));
			code = code / 26 - 1;
		}
		while (code >= 0);
		return value.toString();
	}
136969
def _to_roman(num):
    """"""
    roman_numeral_map = (
        ('M',  1000),
        ('CM', 900),
        ('D',  500),
        ('CD', 400),
        ('C',  100),
        ('XC', 90),
        ('L',  50),
        ('XL', 40),
        ('X',  10),
        ('IX', 9),
        ('V',  5),
        ('IV', 4),
        ('I',  1)
    )
    if not (0 < num < 5000):
        log(WARN, 'Number out of range for roman (must be 1..4999)')
        return str(num)
    result = ''
    for numeral, integer in roman_numeral_map:
        while num >= integer:
            result += numeral
            num -= integer
    return result
946887
public static function toInt($roman)
    {
        if (!preg_match('`[MDCLXVI]+`', strtoupper($roman))) {
            throw new \InvalidArgumentException("$roman is an invalid roman numeral.");
        }
        $roman = strtoupper($roman);

        $characters = array_flip(self::$characters);

        $int = 0;
        while (strlen($roman) > 0) {
            if (isset($characters[substr($roman, 0, 2)])) {
                $int += $characters[substr($roman, 0, 2)];
                $roman = substr($roman, 2);
                continue;
            }
            if (isset($characters[substr($roman, 0, 1)])) {
                $int += $characters[substr($roman, 0, 1)];
                $roman = substr($roman, 1);
                continue;
            }
        }

        return $int;
    }