java.lang.Integer.reverseBytes()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(7.0k)|赞(0)|评价(0)|浏览(195)

本文整理了Java中java.lang.Integer.reverseBytes()方法的一些代码示例,展示了Integer.reverseBytes()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Integer.reverseBytes()方法的具体详情如下:
包路径:java.lang.Integer
类名称:Integer
方法名:reverseBytes

Integer.reverseBytes介绍

[英]Reverses the order of the bytes of the specified integer.
[中]反转指定整数的字节顺序。

代码示例

代码示例来源:origin: netty/netty

  1. /**
  2. * Toggles the endianness of the specified 32-bit integer.
  3. */
  4. public static int swapInt(int value) {
  5. return Integer.reverseBytes(value);
  6. }

代码示例来源:origin: prestodb/presto

  1. @Override
  2. public final int getValueLength(Slice slice, int offset)
  3. {
  4. return Integer.reverseBytes(slice.getInt(offset));
  5. }

代码示例来源:origin: netty/netty

  1. @Override
  2. public final ByteBuf setInt(int index, int value) {
  3. wrapped.checkIndex(index, 4);
  4. _setInt(wrapped, index, nativeByteOrder ? value : Integer.reverseBytes(value));
  5. return this;
  6. }

代码示例来源:origin: netty/netty

  1. @Override
  2. public final int getInt(int index) {
  3. wrapped.checkIndex(index, 4);
  4. int v = _getInt(wrapped, index);
  5. return nativeByteOrder ? v : Integer.reverseBytes(v);
  6. }

代码示例来源:origin: netty/netty

  1. @Override
  2. public final ByteBuf writeInt(int value) {
  3. wrapped.ensureWritable0(4);
  4. _setInt(wrapped, wrapped.writerIndex, nativeByteOrder ? value : Integer.reverseBytes(value));
  5. wrapped.writerIndex += 4;
  6. return this;
  7. }

代码示例来源:origin: prestodb/presto

  1. @Override
  2. public void decodeValueInto(BlockBuilder builder, Slice slice, int offset, int length)
  3. {
  4. int intBits = slice.getInt(offset);
  5. // the file format uses big endian
  6. type.writeLong(builder, Integer.reverseBytes(intBits));
  7. }
  8. }

代码示例来源:origin: google/guava

  1. public void testHashIntReverseBytesVsHashBytesIntsToByteArray() {
  2. int input = 42;
  3. assertEquals(
  4. Hashing.md5().hashBytes(Ints.toByteArray(input)),
  5. Hashing.md5().hashInt(Integer.reverseBytes(input)));
  6. }

代码示例来源:origin: netty/netty

  1. static void setInt(long address, int value) {
  2. if (UNALIGNED) {
  3. PlatformDependent.putInt(address, BIG_ENDIAN_NATIVE_ORDER ? value : Integer.reverseBytes(value));
  4. } else {
  5. PlatformDependent.putByte(address, (byte) (value >>> 24));
  6. PlatformDependent.putByte(address + 1, (byte) (value >>> 16));
  7. PlatformDependent.putByte(address + 2, (byte) (value >>> 8));
  8. PlatformDependent.putByte(address + 3, (byte) value);
  9. }
  10. }

代码示例来源:origin: netty/netty

  1. static void setIntLE(long address, int value) {
  2. if (UNALIGNED) {
  3. PlatformDependent.putInt(address, BIG_ENDIAN_NATIVE_ORDER ? Integer.reverseBytes(value) : value);
  4. } else {
  5. PlatformDependent.putByte(address, (byte) value);
  6. PlatformDependent.putByte(address + 1, (byte) (value >>> 8));
  7. PlatformDependent.putByte(address + 2, (byte) (value >>> 16));
  8. PlatformDependent.putByte(address + 3, (byte) (value >>> 24));
  9. }
  10. }

代码示例来源:origin: netty/netty

  1. static void setIntLE(byte[] array, int index, int value) {
  2. if (UNALIGNED) {
  3. PlatformDependent.putInt(array, index, BIG_ENDIAN_NATIVE_ORDER ? Integer.reverseBytes(value) : value);
  4. } else {
  5. PlatformDependent.putByte(array, index, (byte) value);
  6. PlatformDependent.putByte(array, index + 1, (byte) (value >>> 8));
  7. PlatformDependent.putByte(array, index + 2, (byte) (value >>> 16));
  8. PlatformDependent.putByte(array, index + 3, (byte) (value >>> 24));
  9. }
  10. }

代码示例来源:origin: netty/netty

  1. static int getInt(long address) {
  2. if (UNALIGNED) {
  3. int v = PlatformDependent.getInt(address);
  4. return BIG_ENDIAN_NATIVE_ORDER ? v : Integer.reverseBytes(v);
  5. }
  6. return PlatformDependent.getByte(address) << 24 |
  7. (PlatformDependent.getByte(address + 1) & 0xff) << 16 |
  8. (PlatformDependent.getByte(address + 2) & 0xff) << 8 |
  9. PlatformDependent.getByte(address + 3) & 0xff;
  10. }

代码示例来源:origin: netty/netty

  1. static int getIntLE(long address) {
  2. if (UNALIGNED) {
  3. int v = PlatformDependent.getInt(address);
  4. return BIG_ENDIAN_NATIVE_ORDER ? Integer.reverseBytes(v) : v;
  5. }
  6. return PlatformDependent.getByte(address) & 0xff |
  7. (PlatformDependent.getByte(address + 1) & 0xff) << 8 |
  8. (PlatformDependent.getByte(address + 2) & 0xff) << 16 |
  9. PlatformDependent.getByte(address + 3) << 24;
  10. }

代码示例来源:origin: netty/netty

  1. static int getInt(byte[] array, int index) {
  2. if (UNALIGNED) {
  3. int v = PlatformDependent.getInt(array, index);
  4. return BIG_ENDIAN_NATIVE_ORDER ? v : Integer.reverseBytes(v);
  5. }
  6. return PlatformDependent.getByte(array, index) << 24 |
  7. (PlatformDependent.getByte(array, index + 1) & 0xff) << 16 |
  8. (PlatformDependent.getByte(array, index + 2) & 0xff) << 8 |
  9. PlatformDependent.getByte(array, index + 3) & 0xff;
  10. }

代码示例来源:origin: netty/netty

  1. static int getIntLE(byte[] array, int index) {
  2. if (UNALIGNED) {
  3. int v = PlatformDependent.getInt(array, index);
  4. return BIG_ENDIAN_NATIVE_ORDER ? Integer.reverseBytes(v) : v;
  5. }
  6. return PlatformDependent.getByte(array, index) & 0xff |
  7. (PlatformDependent.getByte(array, index + 1) & 0xff) << 8 |
  8. (PlatformDependent.getByte(array, index + 2) & 0xff) << 16 |
  9. PlatformDependent.getByte(array, index + 3) << 24;
  10. }

代码示例来源:origin: netty/netty

  1. static void setInt(byte[] array, int index, int value) {
  2. if (UNALIGNED) {
  3. PlatformDependent.putInt(array, index, BIG_ENDIAN_NATIVE_ORDER ? value : Integer.reverseBytes(value));
  4. } else {
  5. PlatformDependent.putByte(array, index, (byte) (value >>> 24));
  6. PlatformDependent.putByte(array, index + 1, (byte) (value >>> 16));
  7. PlatformDependent.putByte(array, index + 2, (byte) (value >>> 8));
  8. PlatformDependent.putByte(array, index + 3, (byte) value);
  9. }
  10. }

代码示例来源:origin: prestodb/presto

  1. @Description("encode value as a 32-bit 2's complement big endian varbinary")
  2. @ScalarFunction("to_big_endian_32")
  3. @SqlType(StandardTypes.VARBINARY)
  4. public static Slice toBigEndian32(@SqlType(StandardTypes.INTEGER) long value)
  5. {
  6. Slice slice = Slices.allocate(Integer.BYTES);
  7. slice.setInt(0, Integer.reverseBytes((int) value));
  8. return slice;
  9. }

代码示例来源:origin: prestodb/presto

  1. @Description("encode value as a big endian varbinary according to IEEE 754 single-precision floating-point format")
  2. @ScalarFunction("to_ieee754_32")
  3. @SqlType(StandardTypes.VARBINARY)
  4. public static Slice toIEEE754Binary32(@SqlType(StandardTypes.REAL) long value)
  5. {
  6. Slice slice = Slices.allocate(Float.BYTES);
  7. slice.setInt(0, Integer.reverseBytes((int) value));
  8. return slice;
  9. }

代码示例来源:origin: prestodb/presto

  1. @Description("decode the 32-bit big-endian binary in IEEE 754 single-precision floating-point format")
  2. @ScalarFunction("from_ieee754_32")
  3. @SqlType(StandardTypes.REAL)
  4. public static long fromIEEE754Binary32(@SqlType(StandardTypes.VARBINARY) Slice slice)
  5. {
  6. checkCondition(slice.length() == Integer.BYTES, INVALID_FUNCTION_ARGUMENT, "Input floating-point value must be exactly 4 bytes long");
  7. return Integer.reverseBytes(slice.getInt(0));
  8. }

代码示例来源:origin: prestodb/presto

  1. @Description("decode bigint value from a 32-bit 2's complement big endian varbinary")
  2. @ScalarFunction("from_big_endian_32")
  3. @SqlType(StandardTypes.INTEGER)
  4. public static long fromBigEndian32(@SqlType(StandardTypes.VARBINARY) Slice slice)
  5. {
  6. if (slice.length() != Integer.BYTES) {
  7. throw new PrestoException(INVALID_FUNCTION_ARGUMENT, "expected 4-byte input, but got instead: " + slice.length());
  8. }
  9. return Integer.reverseBytes(slice.getInt(0));
  10. }

代码示例来源:origin: prestodb/presto

  1. @Description("compute SpookyHashV2 32-bit hash")
  2. @ScalarFunction
  3. @SqlType(StandardTypes.VARBINARY)
  4. public static Slice spookyHashV2_32(@SqlType(StandardTypes.VARBINARY) Slice slice)
  5. {
  6. Slice hash = Slices.allocate(Integer.BYTES);
  7. hash.setInt(0, Integer.reverseBytes(SpookyHashV2.hash32(slice, 0, slice.length(), 0)));
  8. return hash;
  9. }

相关文章