Utility function to set sequence numbers in big-endian format
in a byte array.
766290
public static void setBytesFromInt(byte[] bytes,
                                       int    offset,
                                       int    byteCount,
                                       int    value)
    {
        long maxval = ((1L << (8 * byteCount)) - 1);
        if (value > maxval)
        {
            final String msg = "value too large for byteCount";
            IllegalArgumentException iae = new IllegalArgumentException(msg);
            FFDCFilter.processException(
                iae,
                "com.ibm.ws.Transaction.JTA.Util.setBytesFromInt",
                "579");
            throw iae;
        }

        switch (byteCount)
        {
            case 4: bytes[offset++] = (byte) ((value >> 24) & 0xFF);
            case 3: bytes[offset++] = (byte) ((value >> 16) & 0xFF);
            case 2: bytes[offset++] = (byte) ((value >> 8 ) & 0xFF);
            case 1: bytes[offset++] = (byte) ((value      ) & 0xFF);
                break;
            default:
                final String msg = "byteCount is not between 1 and 4";
                IllegalArgumentException iae =
                    new IllegalArgumentException(msg);
                FFDCFilter.processException(
                    iae,
                    "com.ibm.ws.Transaction.JTA.Util.setBytesFromInt",
                    "598");
                throw iae;
        }
    }
1206460
function insertHexadecimalToByteArray (str, buffer, from) {
  for (let i = 0; i < str.length; i += 2) {
    buffer[from] = parseInt(str.substr(i, 2), 16)
    from++
  }
  return buffer
}
637321
public static byte[] getBytesLittleEndian(long value) {
		byte[] b = new byte[8];
		b[0] = (byte)(value & 0xFF);
		b[1] = (byte)((value >> 8) & 0xFF);
		b[2] = (byte)((value >> 16) & 0xFF);
		b[3] = (byte)((value >> 24) & 0xFF);
		b[4] = (byte)((value >> 32) & 0xFF);
		b[5] = (byte)((value >> 40) & 0xFF);
		b[6] = (byte)((value >> 48) & 0xFF);
		b[7] = (byte)((value >> 56) & 0xFF);
		return b;
	}
728449
def generateSequences(n=2048, w=40, sequenceLength=5, sequenceCount=2,
                      sharedRange=None, seed=42):
  
  # Lots of room for noise sdrs
  patternAlphabetSize = 10*(sequenceLength * sequenceCount)
  patternMachine = PatternMachine(n, w, patternAlphabetSize, seed)
  sequenceMachine = SequenceMachine(patternMachine, seed)
  numbers = sequenceMachine.generateNumbers(sequenceCount, sequenceLength,
                                            sharedRange=sharedRange )
  generatedSequences = sequenceMachine.generateFromNumbers(numbers)

  return sequenceMachine, generatedSequences, numbers
749980
private static long byteArrayToLong(byte[] ba, int offset) {
		long l = 0;

		for (int i = 0; i < SIZE_OF_LONG; ++i) {
			l |= (ba[offset + SIZE_OF_LONG - 1 - i] & 0xffL) << (i << 3);
		}

		return l;
	}
1066416
def array_to_native(array, inplace=False):
    
    if numpy.little_endian:
        machine_little = True
    else:
        machine_little = False

    data_little = False
    if array.dtype.names is None:

        if array.dtype.base.byteorder == '|':
            # strings and 1 byte integers
            return array

        data_little = is_little_endian(array)
    else:
        # assume all are same byte order: we only need to find one with
        # little endian
        for fname in array.dtype.names:
            if is_little_endian(array[fname]):
                data_little = True
                break

    if ((machine_little and not data_little)
            or (not machine_little and data_little)):
        output = array.byteswap(inplace)
    else:
        output = array

    return output
255313
public static void writeLong(byte b[], int offset, long value) {
    b[offset++] = (byte) (value >>> 56);
    b[offset++] = (byte) (value >>> 48);
    b[offset++] = (byte) (value >>> 40);
    b[offset++] = (byte) (value >>> 32);
    b[offset++] = (byte) (value >>> 24);
    b[offset++] = (byte) (value >>> 16);
    b[offset++] = (byte) (value >>> 8);
    b[offset] = (byte)value;
  }
724703
public static long toLong(byte[] b) {
        return ((((long) b[7]) & 0xFF)
                + ((((long) b[6]) & 0xFF) << 8)
                + ((((long) b[5]) & 0xFF) << 16)
                + ((((long) b[4]) & 0xFF) << 24)
                + ((((long) b[3]) & 0xFF) << 32)
                + ((((long) b[2]) & 0xFF) << 40)
                + ((((long) b[1]) & 0xFF) << 48)
                + ((((long) b[0]) & 0xFF) << 56));
    }
1314905
public static int decodeSequence(byte[] flakeBytes) {
        ByteBuffer buffer = ByteBuffer.allocate(16);
        buffer.put(flakeBytes);
        buffer.flip();
        buffer.getLong();
        return (int)(buffer.getLong() & 0x000000000000FFFF);
    }
447440
def number_to_lower_endian(n, base):
  """"""
  if n < base:
    return [n]
  return [n % base] + number_to_lower_endian(n // base, base)
522646
def unpack_int64_bigendian(bytes)
      bytes.each_byte.to_a.reverse.each_with_index.
        reduce(0) { |val, (byte, index)| val | (byte << (index * 8)) }
    end
161691
private static function set_endianness()
  {
    $packed = pack('d', 1);
    switch ($packed)
    {
      case "\77\360\0\0\0\0\0\0":
        self::$endianness = self::BIG_ENDIAN;
        break;
      case "\0\0\0\0\0\0\360\77":
        self::$endianness = self::LITTLE_ENDIAN;
        break;
      default:
        throw new AvroException(
          sprintf('Error determining platform endianness: %s',
                  AvroDebug::hex_string($packed)));
    }
  }
347012
function readBytes(arr, n) {
		var i, ret = [];
		for (i = 0; i < n; i += 1) {
			ret.push(arr.shift());
		}

		return ret;
	}
1145969
public static byte[] toBytes(CharSequence seq) {
    try {
      return seq.toString().getBytes("UTF-8");
    }
    catch (UnsupportedEncodingException ex) {
      throw new RuntimeException(ex); // shouldn't happen since UTF-8 is supported by all JVMs per spec
    }
  }
176755
function uint32BEtoNumber(bytes) {
  let n = 0;
  for (let i = 0; i < 3; i++) {
    n |= bytes[i];
    n <<= 8;
  }
  n |= bytes[3];
  return n;
}
1147350
public int[] buildSuffixArray(CharSequence sequence) {
        /*
         * Allocate slightly more space, some suffix construction strategies need it and
         * we don't want to waste space for multiple symbol mappings.
         */

        this.input = new int[sequence.length() + SuffixArrays.MAX_EXTRA_TRAILING_SPACE];
        for (int i = sequence.length() - 1; i >= 0; i--) {
            input[i] = sequence.charAt(i);
        }

        final int start = 0;
        final int length = sequence.length();

        final ISymbolMapper mapper = new DensePositiveMapper(input, start, length);
        mapper.map(input, start, length);

        return delegate.buildSuffixArray(input, start, length);
    }
281227
public static int getNumSetBits(ByteBuffer bfBuffer, int start)
  {
    ByteBuffer view = bfBuffer.duplicate().order(ByteOrder.BIG_ENDIAN);
    view.position(start);
    int numLongs = view.getInt(1 + start);
    int setBits = 0;
    for (int i = 0, pos = START_OF_SERIALIZED_LONGS + start; i < numLongs; i++, pos += Long.BYTES) {
      setBits += Long.bitCount(view.getLong(pos));
    }
    return setBits;
  }