swaps bytes for 16 bit, leaves remaining trailing bytes alone
497862
def _swap_bytes(data):
    """"""

    a, b = data[1::2], data[::2]
    data = bytearray().join(bytearray(x) for x in zip(a, b))
    if len(b) > len(a):
        data += b[-1:]
    return bytes(data)
1166321
def _not16(ins):
    ''' 
    '''
    output = _16bit_oper(ins.quad[2])
    output.append('ld a, h')
    output.append('or l')
    output.append('sub 1')
    output.append('sbc a, a')
    output.append('push af')
    return output
845652
function byteswap64(buf) {
  var swap = new Buffer(buf.length);
  for (var i = 0; i < buf.length; i++) {
    swap[i] = buf[buf.length -1 - i];
  }
  return swap;
}
1265819
def crc16(data):
    
    m_crc = 0xffff
    for this in data:
        m_crc ^= ord_byte(this)
        for _ in range(8):
            j = m_crc & 1
            m_crc >>= 1
            if j:
                m_crc ^= 0x8408
    return m_crc
77473
function unpack (bits, offset, length) {
    var mask = 0xffffffff, shift
    mask = mask >>> (32 - bits)
    mask = mask >>> (bits - length)
    shift = bits - offset - length
    shift = shift ? 'value >>> ' + shift : 'value'
    return shift + ' & 0x' + mask.toString(16)
}
606232
private double bytesToDouble(byte[] bytes) {
        ByteBuffer original = byteArrayToByteBuffer(bytes);

        if (bytes.length < BYTES_IN_DOUBLE) {
            ByteBuffer byteBuffer = ByteBuffer.allocate(BYTES_IN_DOUBLE);
            if (sasFileProperties.getEndianness() == 1) {
                byteBuffer.position(BYTES_IN_DOUBLE - bytes.length);
            }
            byteBuffer.put(original);
            byteBuffer.order(original.order());
            byteBuffer.position(0);
            original = byteBuffer;
        }

        return original.getDouble();
    }
644762
public static void intToBytes(int value, byte[] bytes, int offset) {
        bytes[offset + 3] = (byte) (value >>> 0);
        bytes[offset + 2] = (byte) (value >>> 8);
        bytes[offset + 1] = (byte) (value >>> 16);
        bytes[offset + 0] = (byte) (value >>> 24);
    }
387760
private static int get16(byte[] b, int off) {
        return Byte.toUnsignedInt(b[off]) | ( Byte.toUnsignedInt(b[off+1]) << 8);
    }
545067
def dump_uint_b_into(n, width, buffer, offset=0):
    
    for idx in range(width):
        buffer[idx + offset] = n & 0xff
        n >>= 8
    return buffer
1236011
def _double_as_bytes(dval):
    ""
    tmp = list(struct.unpack('8B',struct.pack('d', dval)))
    if not _big_endian:
        tmp.reverse()
    return tmp
598163
private static void bytesToHex(byte[] bytes, byte[] hex, int offset) {
    final char[] lookup =
        {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};

    int i;
    int c;
    int j;
    int pos = offset;

    for (i = 0; i < 16; i++) {
      c = bytes[i] & 0xFF;
      j = c >> 4;
      hex[pos++] = (byte) lookup[j];
      j = (c & 0xF);
      hex[pos++] = (byte) lookup[j];
    }
  }
452534
function(bytesIn,start,end,mode)
	{
		if(end - start > 16)
			end = start + 16;
		
		return bytesIn.slice(start, end);
	}
399074
def offset_byte_in_data(target_data, offset, target_byte_pos, readable = False, wraparound = False):
    
    byte_pos = target_byte_pos * 2
    prefix = target_data[:byte_pos]
    suffix = target_data[byte_pos+2:]
    target_byte = target_data[byte_pos:byte_pos+2]
    int_value = int(target_byte, 16)
    int_value += offset

    # Wraparound
    if int_value > 255 and wraparound:
        int_value -= 256

    # Extract readable char for analysis
    if readable:
        if int_value < 256 and int_value > 0:
            offset_byte = get_readable_string(int_value)
        else:
            offset_byte = int_to_padded_hex_byte(int_value)
    else:
        offset_byte = int_to_padded_hex_byte(int_value)

    return ''.join([prefix, offset_byte, suffix])
665112
def _unbytes(bytestr):
    
    return ''.join(chr(int(bytestr[k:k + 2], 16))
                   for k in range(0, len(bytestr), 2))
878402
private static int offsetOf65KUtf8Bytes(String str, int startIndex, int endIndex) {
    // This implementation is based off of Utf8.encodedLength
    int utf8Length = 0;
    int i = startIndex;
    for (; i < endIndex; i++) {
      char c = str.charAt(i);
      utf8Length++;
      if (c < 0x800) {
        utf8Length += (0x7f - c) >>> 31; // branch free!
      } else {
        utf8Length += Character.isSurrogate(c) ? 1 : 2;
      }
      if (utf8Length == MAX_CONSTANT_STRING_LENGTH) {
        return i + 1;
      } else if (utf8Length > MAX_CONSTANT_STRING_LENGTH) {
        return i;
      }
    }
    return endIndex;
  }
790830
def read_int16(self, little_endian=True):
        
        if little_endian:
            endian = "<"
        else:
            endian = ">"
        return self.unpack('%sh' % endian, 2)
1087224
function amf3decUI29(buf) {
    var val = 0;
    var len = 1;
    var b;

    do {
        b = buf.readUInt8(len++);
        val = (val << 7) + (b & 0x7F);
    } while (len < 5 || b > 0x7F);

    if (len == 5) val = val | b; // Preserve the major bit of the last byte

    return { len: len, value: val }
}