Outputs a histogram as bytes using a particularly cheesy encoding.
184140
@Override
    public void asBytes(ByteBuffer buf) {
        buf.putInt(VERBOSE_ENCODING);
        buf.putDouble(min);
        buf.putDouble(max);
        buf.putDouble((float) compression());
        buf.putInt(summary.size());
        for (Centroid centroid : summary) {
            buf.putDouble(centroid.mean());
        }

        for (Centroid centroid : summary) {
            buf.putInt(centroid.count());
        }
    }
309077
def convert_bytes(b):
    ''''''
    if b is None:
        return '#NA'
    for s in reversed(memory_symbols):
        if b >= memory_size[s]:
            value = float(b) / memory_size[s]
            return '%.1f%sB' % (value, s)
    return "%sB" % b
838264
def rewrap_bytes(data):
    '''
    '''
    return b'\n'.join(
        data[index:index+70] for index in range(0, len(data), 70)
    )
124511
static private void encodeLastByte(byte last, int byteIndex, StringBuilder output) {
        int chunk;
        int offset = byteIndex % 5;
        switch (offset) {
            case 0:
                chunk = ((last & 0x07) << 2);
                output.append(lookupTable.charAt(chunk));
                break;
            case 1:
                chunk = ((last & 0x01) << 4);
                output.append(lookupTable.charAt(chunk));
                break;
            case 2:
                chunk = ((last & 0x0F) << 1);
                output.append(lookupTable.charAt(chunk));
                break;
            case 3:
                chunk = ((last & 0x03) << 3);
                output.append(lookupTable.charAt(chunk));
                break;
            case 4:
                break;
        }
    }
1019104
def quantize(image, bits_per_channel=None):

    ''''''

    if bits_per_channel is None:
        bits_per_channel = 6

    assert image.dtype == np.uint8

    shift = 8-bits_per_channel
    halfbin = (1 << shift) >> 1

    return ((image.astype(int) >> shift) << shift) + halfbin
993013
def hexdump(x, dump=False):
    
    s = ""
    x = bytes_encode(x)
    x_len = len(x)
    i = 0
    while i < x_len:
        s += "%04x  " % i
        for j in range(16):
            if i + j < x_len:
                s += "%02X " % orb(x[i + j])
            else:
                s += "   "
        s += " %s\n" % sane_color(x[i:i + 16])
        i += 16
    # remove trailing \n
    s = s[:-1] if s.endswith("\n") else s
    if dump:
        return s
    else:
        print(s)
930419
def to_bytes(s, encoding="utf-8"):
    
    if isinstance(s, six.binary_type):
        return s
    else:
        return six.text_type(s).encode(encoding)
857802
def xtob(data, sep=''):
    """"""
    # remove the non-hex characters
    data = re.sub("[^0-9a-fA-F]", '', data)

    # interpret the hex
    return binascii.unhexlify(data)
771502
public static String toHex(byte[] bytes) {
    StringBuffer buffer = new StringBuffer();

    for (byte b : bytes) {
      buffer.append(String.format("%02X", b));
    }

    return buffer.toString();
  }
830817
def serialize_bytes(data):
        """"""
        if not isinstance(data, bytes):
            if isinstance(data, str):
                data = data.encode('utf-8')
            else:
                raise TypeError(
                    'bytes or str expected, not {}'.format(type(data)))

        r = []
        if len(data) < 254:
            padding = (len(data) + 1) % 4
            if padding != 0:
                padding = 4 - padding

            r.append(bytes([len(data)]))
            r.append(data)

        else:
            padding = len(data) % 4
            if padding != 0:
                padding = 4 - padding

            r.append(bytes([
                254,
                len(data) % 256,
                (len(data) >> 8) % 256,
                (len(data) >> 16) % 256
            ]))
            r.append(data)

        r.append(bytes(padding))
        return b''.join(r)
653118
def hexdumpLine (bytes, length=None):
  
  line = ""

  if length is None:
    length = len(bytes)

  for n in xrange(0, length, 2):
    if n < len(bytes) - 1:
      line += "%02x%02x  " % (bytes[n], bytes[n + 1])
    elif n < len(bytes):
      line += "%02x    "   % bytes[n]
    else:
      line += "      "

  line += "*"

  for n in xrange(length):
    if n < len(bytes):
      if bytes[n] in xrange(32, 127):
        line += "%c" % bytes[n]
      else:
        line += "."
    else:
      line += " "

  line += "*"
  return line
1098382
private void writeImageDataHexEncoded(final OutputStream bab) throws IOException
    {
    	int cnt = 0;
    	for(int k = 0; k < imageData.length; k++) {
    		final byte[] chunk = imageData[k];
			for(int x = 0; x < chunk.length; x++) {
				bab.write(byte2charLUT, (chunk[x]&0xff)*2, 2);
				if(++cnt == 64) {
					bab.write('\n');
					cnt = 0;
				}
			}
		}    	
   		if(cnt > 0) bab.write('\n');
    }
234531
def to_bytes(self):
		
		chunks = [PNG_SIGN]
		chunks.extend(c[1] for c in self.chunks)
		return b"".join(chunks)
330454
def _bytes_to_json(value):
    """"""
    if isinstance(value, bytes):
        value = base64.standard_b64encode(value).decode("ascii")
    return value
1275684
def pretty_bytes(num):
    
    for unit in ['', 'KB', 'MB', 'GB']:
        if num < 1024.0:
            if unit == '':
                return "%d" % (num)
            else:
                return "%3.1f%s" % (num, unit)
        num /= 1024.0
    return "%3.1f%s" % (num, 'TB')
114168
static private void encodeBytes(byte previous, byte current, int byteIndex, StringBuilder output) {
        int chunk;
        int offset = byteIndex % 5;
        switch (offset) {
            case 0:
                chunk = ((current & 0xF8) >>> 3);
                output.append(lookupTable.charAt(chunk));
                break;
            case 1:
                chunk = (((previous & 0x07) << 2) | ((current & 0xC0) >>> 6));
                output.append(lookupTable.charAt(chunk));
                chunk = ((current & 0x3E) >>> 1);
                output.append(lookupTable.charAt(chunk));
                break;
            case 2:
                chunk = (((previous & 0x01) << 4) | ((current & 0xF0) >>> 4));
                output.append(lookupTable.charAt(chunk));
                break;
            case 3:
                chunk = (((previous & 0x0F) << 1) | ((current & 0x80) >>> 7));
                output.append(lookupTable.charAt(chunk));
                chunk = ((current & 0x7C) >>> 2);
                output.append(lookupTable.charAt(chunk));
                break;
            case 4:
                chunk = (((previous & 0x03) << 3) | ((current & 0xE0) >>> 5));
                output.append(lookupTable.charAt(chunk));
                chunk = (current & 0x1F);
                output.append(lookupTable.charAt(chunk));
                break;
        }
    }
480347
def encode(self, data):
        ''''''
        if isinstance(data, str):
            data = bytearray(data, "latin-1")
        chunk_size = self.nsize - self.nsym
        enc = bytearray()
        for i in xrange(0, len(data), chunk_size):
            chunk = data[i:i+chunk_size]
            enc.extend(rs_encode_msg(chunk, self.nsym, fcr=self.fcr, generator=self.generator))
        return enc