10进制转化成62进制以内的进制 convert 10 binary to customized binary, max is 62
766575
function binaryTransfer(integer, binary) {
	binary = binary || 62;
	var stack = [];
	var num;
	var result = '';
	var sign = integer < 0 ? '-' : '';
	
	function table (num) {
		var t = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
		return t[num];
	}
	
	integer = Math.abs(integer);
	
	while (integer >= binary) {
		num = integer % binary;
		integer = Math.floor(integer / binary);
		stack.push(table(num));
	}
	
	if (integer > 0) {
		stack.push(table(integer));
	}
	
	for (var i = stack.length - 1; i >= 0; i--) {
		result += stack[i];
	} 
	
	return sign + result;
}
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;
    }
1253422
def str_to_num(self, arg):
        

        if len(arg) == 1:
            ten = '10'
        else:
            ten = ''
        switcher = {
            '一': '1',
            '二': '2',
            '三': '3',
            '四': '4',
            '五': '5',
            '六': '6',
            '七': '7',
            '八': '8',
            '九': '9',
            '十': ten,
            '〇': '0',
            '○': '0',
        }
        test = ''
        for i in arg:
            test = test + switcher.get(i, None)
        return int(test)
1221276
def int_to_bin(i):
    
    # devide in two parts (bytes)
    i1 = i % 256
    i2 = int(i / 256)
    # make string (little endian)
    return chr(i1) + chr(i2)
950304
def truncate(hmac_result, length=6):
    
    assert(len(hmac_result) == 20)
    offset   =  ord(hmac_result[19]) & 0xf
    bin_code = (ord(hmac_result[offset]) & 0x7f) << 24 \
        | (ord(hmac_result[offset+1]) & 0xff) << 16 \
        | (ord(hmac_result[offset+2]) & 0xff) <<  8 \
        | (ord(hmac_result[offset+3]) & 0xff)
    return bin_code % (10 ** length)
1044705
private StringBuilder adjustBinaryString(String binaryString, boolean compact, int layers) {

        StringBuilder adjustedString = new StringBuilder();
        int codewordSize = getCodewordSize(layers);

        for (int i = 0, j = 0; i < binaryString.length(); ) {
            if (((j + 1) % codewordSize) == 0) {
                /* Last bit of codeword */
                boolean done = false;
                int ones = 0;
                for (int t = 0; t < (codewordSize - 1); t++) {
                    if (binaryString.charAt((i - (codewordSize - 1)) + t) == '1') {
                        ones++;
                    }
                }
                if (ones == (codewordSize - 1)) {
                    adjustedString.append('0');
                    j++;
                    done = true;
                }
                if (ones == 0) {
                    adjustedString.append('1');
                    j++;
                    done = true;
                }
                if (!done) {
                    adjustedString.append(binaryString.charAt(i));
                    j++;
                    i++;
                }
            } else {
                adjustedString.append(binaryString.charAt(i));
                j++;
                i++;
            }
        }

        int adjustedLength = adjustedString.length();
        int remainder = adjustedLength % codewordSize;

        /* Add padding */
        int padBits = codewordSize - remainder;
        if (padBits == codewordSize) {
            padBits = 0;
        }
        for (int i = 0; i < padBits; i++) {
            adjustedString.append('1');
        }
        adjustedLength = adjustedString.length();

        /* Make sure padding didn't create an invalid (all 1s) codeword */
        int count = 0;
        for (int i = Math.max(adjustedLength - codewordSize, 0); i < adjustedLength; i++) {
            if (adjustedString.charAt(i) == '1') {
                count++;
            }
        }
        if (count == codewordSize) {
            adjustedString.setCharAt(adjustedLength - 1, '0');
        }

        /* Check if the data actually fits into the selected symbol size */
        int dataMaxSize;
        if (compact) {
            dataMaxSize = codewordSize * (AZTEC_COMPACT_SIZES[layers - 1] - 3);
        } else {
            dataMaxSize = codewordSize * (AZTEC_SIZES[layers - 1] - 3);
        }

        if (adjustedLength > dataMaxSize) {
            throw new OkapiException("Data too long for specified Aztec Code symbol size");
        }

        /* Log the codewords */
        encodeInfo += "Codewords: ";
        for (int i = 0; i < (adjustedLength / codewordSize); i++) {
            int l = 0, m = (1 << (codewordSize - 1));
            for (int j = 0; j < codewordSize; j++) {
                if (adjustedString.charAt((i * codewordSize) + j) == '1') {
                    l += m;
                }
                m = m >> 1;
            }
            encodeInfo += Integer.toString(l) + " ";
        }
        encodeInfo += "\n";

        /* Return the adjusted bit string */
        return adjustedString;
    }
1283004
def asBinary(self):
        
        binString = binary.bin(self._value)[2:]
        return '0' * (len(self._value) - len(binString)) + binString
1100132
function (str) {
        var bin = [];
        for(var i = 0; i < str.length * 8; i += 8)
        {
            bin[i>>5] |= (str.charCodeAt(i / 8) & 255) << (i%32);
        }
        return bin;
    }
1251572
static String byteToBinaryString(byte b, int limit) {
    final StringBuilder sb = new StringBuilder();
    if (limit > 8) {
      limit = 8;
    }
    for (int i = 0; i < limit; i++) {
      sb.append((char)('0' + (b&1)));
      b>>=1;
    }
    return sb.toString();
  }
792683
function bininputtobin(bininput){
  var len = bininput.length;
  if(len == 0){return filledarray(false, 1);}
  var bin = new Array(len);
  var j = 0;
  for (var i = 0; i < len; i++){
    switch (bininput[i]){
    case '0': bin[j++] = false; break;
    case '1': bin[j++] = true; break;
    default: break;
    }
  }
  return removezeros(bin.slice(0, j));
}
1150404
function (binarray) {
        var hex_tab = "0123456789abcdef";
        var str = "";
        for(var i = 0; i < binarray.length * 4; i++)
        {
            str += hex_tab.charAt((binarray[i>>2] >> ((i%4)*8+4)) & 0xF) +
                hex_tab.charAt((binarray[i>>2] >> ((i%4)*8  )) & 0xF);
        }
        return str;
    }
969276
public static long bytesToLong(byte[] b)
    {
        long l = ((long) b[0] << 56) & 0xFF00000000000000L;
        // 如果不强制转换为long，那么默认会当作int，导致最高32位丢失
        l |= ((long) b[1] << 48) & 0xFF000000000000L;
        l |= ((long) b[2] << 40) & 0xFF0000000000L;
        l |= ((long) b[3] << 32) & 0xFF00000000L;
        l |= ((long) b[4] << 24) & 0xFF000000L;
        l |= ((long) b[5] << 16) & 0xFF0000L;
        l |= ((long) b[6] << 8) & 0xFF00L;
        l |= (long) b[7] & 0xFFL;
        return l;
    }
96982
function hexinputtobin(hexinput){
  var len = hexinput.length;
  if(len == 0){return filledarray(false, 1);}
  var bin = new Array(len * 4);
  var j = 0;
  for (var i = 0; i < len; i++){
    switch (hexinput[i]){
    case '0':           bin[j+0] = false; bin[j+1] = false; bin[j+2] = false; bin[j+3] = false; j+=4; break;
    case '1':           bin[j+0] = false; bin[j+1] = false; bin[j+2] = false; bin[j+3] = true;  j+=4; break;
    case '2':           bin[j+0] = false; bin[j+1] = false; bin[j+2] = true;  bin[j+3] = false; j+=4; break;
    case '3':           bin[j+0] = false; bin[j+1] = false; bin[j+2] = true;  bin[j+3] = true;  j+=4; break;
    case '4':           bin[j+0] = false; bin[j+1] = true;  bin[j+2] = false; bin[j+3] = false; j+=4; break;
    case '5':           bin[j+0] = false; bin[j+1] = true;  bin[j+2] = false; bin[j+3] = true;  j+=4; break;
    case '6':           bin[j+0] = false; bin[j+1] = true;  bin[j+2] = true;  bin[j+3] = false; j+=4; break;
    case '7':           bin[j+0] = false; bin[j+1] = true;  bin[j+2] = true;  bin[j+3] = true;  j+=4; break;
    case '8':           bin[j+0] = true;  bin[j+1] = false; bin[j+2] = false; bin[j+3] = false; j+=4; break;
    case '9':           bin[j+0] = true;  bin[j+1] = false; bin[j+2] = false; bin[j+3] = true;  j+=4; break;
    case 'a': case 'A': bin[j+0] = true;  bin[j+1] = false; bin[j+2] = true;  bin[j+3] = false; j+=4; break;
    case 'b': case 'B': bin[j+0] = true;  bin[j+1] = false; bin[j+2] = true;  bin[j+3] = true;  j+=4; break;
    case 'c': case 'C': bin[j+0] = true;  bin[j+1] = true;  bin[j+2] = false; bin[j+3] = false; j+=4; break;
    case 'd': case 'D': bin[j+0] = true;  bin[j+1] = true;  bin[j+2] = false; bin[j+3] = true;  j+=4; break;
    case 'e': case 'E': bin[j+0] = true;  bin[j+1] = true;  bin[j+2] = true;  bin[j+3] = false; j+=4; break;
    case 'f': case 'F': bin[j+0] = true;  bin[j+1] = true;  bin[j+2] = true;  bin[j+3] = true;  j+=4; break;
    default: break;
    }
  }
  return removezeros(bin.slice(0, j));
}
1234331
function decinputtobin(decinput){
  var len = decinput.length;
  if(len == 0){return filledarray(false, 1);}
  var bin = new Array();
  var digit = new Array(4);
  for (var i = 0; i < len; i++){
    switch (decinput[i]){
    case '0': digit[0] = false; digit[1] = false; digit[2] = false; digit[3] = false; break;
    case '1': digit[0] = false; digit[1] = false; digit[2] = false; digit[3] = true;  break;
    case '2': digit[0] = false; digit[1] = false; digit[2] = true;  digit[3] = false; break;
    case '3': digit[0] = false; digit[1] = false; digit[2] = true;  digit[3] = true;  break;
    case '4': digit[0] = false; digit[1] = true;  digit[2] = false; digit[3] = false; break;
    case '5': digit[0] = false; digit[1] = true;  digit[2] = false; digit[3] = true;  break;
    case '6': digit[0] = false; digit[1] = true;  digit[2] = true;  digit[3] = false; break;
    case '7': digit[0] = false; digit[1] = true;  digit[2] = true;  digit[3] = true;  break;
    case '8': digit[0] = true;  digit[1] = false; digit[2] = false; digit[3] = false; break;
    case '9': digit[0] = true;  digit[1] = false; digit[2] = false; digit[3] = true;  break;
    default: continue;
    }
    bin = binadd(binten(bin), digit);
  }
  return removezeros(bin);
}
317637
function(_binarray){
        var _index = 0,
            _result = [],
            _mode = _binarray.length%3;
        // this is for the padding
        if (_mode==1)
            _binarray.push(0,0);
        if (_mode==2)
            _binarray.push(0);
        // from here conversion
        while(_index<_binarray.length){
            _result.push(__b64char[_binarray[_index]>>2],
                         __b64char[((_binarray[_index]&3)<<4)|(_binarray[_index+1]>>4)],
                         __b64char[((_binarray[_index+1]&15)<<2)|(_binarray[_index+2]>>6)],
                         __b64char[_binarray[_index+2]&63]);
            _index += 3;
        }
        // this is again for the padding
        if (_mode == 1)
            _result[_result.length-1] =
            _result[_result.length-2] = '=';
        if (_mode == 2)
            _result[_result.length-1] = '=';
        // we join the array to return a textstring
        return _result.join('');
    }
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
959749
private int encode928(int bitLng) {
        int i, j, b, bitCnt, cwNdx, cwCnt, cwLng;
        for (cwNdx = cwLng = b = 0; b < bitLng; b += 69, cwNdx += 7) {
            bitCnt = min(bitLng - b, 69);
            cwLng += cwCnt = bitCnt / 10 + 1;
            for (i = 0; i < cwCnt; i++) {
                codeWords[cwNdx + i] = 0; /* init 0 */
            }
            for (i = 0; i < bitCnt; i++) {
                if (getBit(b + bitCnt - i - 1)) {
                    for (j = 0; j < cwCnt; j++) {
                        codeWords[cwNdx + j] += pwr928[i][j + 7 - cwCnt];
                    }
                }
            }
            for (i = cwCnt - 1; i > 0; i--) {
                /* add "carries" */
                codeWords[cwNdx + i - 1] += codeWords[cwNdx + i] / 928L;
                codeWords[cwNdx + i] %= 928L;
            }
        }
        return (cwLng);
    }