本文整理了Java中java.lang.Integer.reverseBytes()
方法的一些代码示例,展示了Integer.reverseBytes()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Integer.reverseBytes()
方法的具体详情如下:
包路径:java.lang.Integer
类名称:Integer
方法名:reverseBytes
[英]Reverses the order of the bytes of the specified integer.
[中]反转指定整数的字节顺序。
代码示例来源:origin: netty/netty
/**
* Toggles the endianness of the specified 32-bit integer.
*/
public static int swapInt(int value) {
return Integer.reverseBytes(value);
}
代码示例来源:origin: prestodb/presto
@Override
public final int getValueLength(Slice slice, int offset)
{
return Integer.reverseBytes(slice.getInt(offset));
}
代码示例来源:origin: netty/netty
@Override
public final ByteBuf setInt(int index, int value) {
wrapped.checkIndex(index, 4);
_setInt(wrapped, index, nativeByteOrder ? value : Integer.reverseBytes(value));
return this;
}
代码示例来源:origin: netty/netty
@Override
public final int getInt(int index) {
wrapped.checkIndex(index, 4);
int v = _getInt(wrapped, index);
return nativeByteOrder ? v : Integer.reverseBytes(v);
}
代码示例来源:origin: netty/netty
@Override
public final ByteBuf writeInt(int value) {
wrapped.ensureWritable0(4);
_setInt(wrapped, wrapped.writerIndex, nativeByteOrder ? value : Integer.reverseBytes(value));
wrapped.writerIndex += 4;
return this;
}
代码示例来源:origin: prestodb/presto
@Override
public void decodeValueInto(BlockBuilder builder, Slice slice, int offset, int length)
{
int intBits = slice.getInt(offset);
// the file format uses big endian
type.writeLong(builder, Integer.reverseBytes(intBits));
}
}
代码示例来源:origin: google/guava
public void testHashIntReverseBytesVsHashBytesIntsToByteArray() {
int input = 42;
assertEquals(
Hashing.md5().hashBytes(Ints.toByteArray(input)),
Hashing.md5().hashInt(Integer.reverseBytes(input)));
}
代码示例来源:origin: netty/netty
static void setInt(long address, int value) {
if (UNALIGNED) {
PlatformDependent.putInt(address, BIG_ENDIAN_NATIVE_ORDER ? value : Integer.reverseBytes(value));
} else {
PlatformDependent.putByte(address, (byte) (value >>> 24));
PlatformDependent.putByte(address + 1, (byte) (value >>> 16));
PlatformDependent.putByte(address + 2, (byte) (value >>> 8));
PlatformDependent.putByte(address + 3, (byte) value);
}
}
代码示例来源:origin: netty/netty
static void setIntLE(long address, int value) {
if (UNALIGNED) {
PlatformDependent.putInt(address, BIG_ENDIAN_NATIVE_ORDER ? Integer.reverseBytes(value) : value);
} else {
PlatformDependent.putByte(address, (byte) value);
PlatformDependent.putByte(address + 1, (byte) (value >>> 8));
PlatformDependent.putByte(address + 2, (byte) (value >>> 16));
PlatformDependent.putByte(address + 3, (byte) (value >>> 24));
}
}
代码示例来源:origin: netty/netty
static void setIntLE(byte[] array, int index, int value) {
if (UNALIGNED) {
PlatformDependent.putInt(array, index, BIG_ENDIAN_NATIVE_ORDER ? Integer.reverseBytes(value) : value);
} else {
PlatformDependent.putByte(array, index, (byte) value);
PlatformDependent.putByte(array, index + 1, (byte) (value >>> 8));
PlatformDependent.putByte(array, index + 2, (byte) (value >>> 16));
PlatformDependent.putByte(array, index + 3, (byte) (value >>> 24));
}
}
代码示例来源:origin: netty/netty
static int getInt(long address) {
if (UNALIGNED) {
int v = PlatformDependent.getInt(address);
return BIG_ENDIAN_NATIVE_ORDER ? v : Integer.reverseBytes(v);
}
return PlatformDependent.getByte(address) << 24 |
(PlatformDependent.getByte(address + 1) & 0xff) << 16 |
(PlatformDependent.getByte(address + 2) & 0xff) << 8 |
PlatformDependent.getByte(address + 3) & 0xff;
}
代码示例来源:origin: netty/netty
static int getIntLE(long address) {
if (UNALIGNED) {
int v = PlatformDependent.getInt(address);
return BIG_ENDIAN_NATIVE_ORDER ? Integer.reverseBytes(v) : v;
}
return PlatformDependent.getByte(address) & 0xff |
(PlatformDependent.getByte(address + 1) & 0xff) << 8 |
(PlatformDependent.getByte(address + 2) & 0xff) << 16 |
PlatformDependent.getByte(address + 3) << 24;
}
代码示例来源:origin: netty/netty
static int getInt(byte[] array, int index) {
if (UNALIGNED) {
int v = PlatformDependent.getInt(array, index);
return BIG_ENDIAN_NATIVE_ORDER ? v : Integer.reverseBytes(v);
}
return PlatformDependent.getByte(array, index) << 24 |
(PlatformDependent.getByte(array, index + 1) & 0xff) << 16 |
(PlatformDependent.getByte(array, index + 2) & 0xff) << 8 |
PlatformDependent.getByte(array, index + 3) & 0xff;
}
代码示例来源:origin: netty/netty
static int getIntLE(byte[] array, int index) {
if (UNALIGNED) {
int v = PlatformDependent.getInt(array, index);
return BIG_ENDIAN_NATIVE_ORDER ? Integer.reverseBytes(v) : v;
}
return PlatformDependent.getByte(array, index) & 0xff |
(PlatformDependent.getByte(array, index + 1) & 0xff) << 8 |
(PlatformDependent.getByte(array, index + 2) & 0xff) << 16 |
PlatformDependent.getByte(array, index + 3) << 24;
}
代码示例来源:origin: netty/netty
static void setInt(byte[] array, int index, int value) {
if (UNALIGNED) {
PlatformDependent.putInt(array, index, BIG_ENDIAN_NATIVE_ORDER ? value : Integer.reverseBytes(value));
} else {
PlatformDependent.putByte(array, index, (byte) (value >>> 24));
PlatformDependent.putByte(array, index + 1, (byte) (value >>> 16));
PlatformDependent.putByte(array, index + 2, (byte) (value >>> 8));
PlatformDependent.putByte(array, index + 3, (byte) value);
}
}
代码示例来源:origin: prestodb/presto
@Description("encode value as a 32-bit 2's complement big endian varbinary")
@ScalarFunction("to_big_endian_32")
@SqlType(StandardTypes.VARBINARY)
public static Slice toBigEndian32(@SqlType(StandardTypes.INTEGER) long value)
{
Slice slice = Slices.allocate(Integer.BYTES);
slice.setInt(0, Integer.reverseBytes((int) value));
return slice;
}
代码示例来源:origin: prestodb/presto
@Description("encode value as a big endian varbinary according to IEEE 754 single-precision floating-point format")
@ScalarFunction("to_ieee754_32")
@SqlType(StandardTypes.VARBINARY)
public static Slice toIEEE754Binary32(@SqlType(StandardTypes.REAL) long value)
{
Slice slice = Slices.allocate(Float.BYTES);
slice.setInt(0, Integer.reverseBytes((int) value));
return slice;
}
代码示例来源:origin: prestodb/presto
@Description("decode the 32-bit big-endian binary in IEEE 754 single-precision floating-point format")
@ScalarFunction("from_ieee754_32")
@SqlType(StandardTypes.REAL)
public static long fromIEEE754Binary32(@SqlType(StandardTypes.VARBINARY) Slice slice)
{
checkCondition(slice.length() == Integer.BYTES, INVALID_FUNCTION_ARGUMENT, "Input floating-point value must be exactly 4 bytes long");
return Integer.reverseBytes(slice.getInt(0));
}
代码示例来源:origin: prestodb/presto
@Description("decode bigint value from a 32-bit 2's complement big endian varbinary")
@ScalarFunction("from_big_endian_32")
@SqlType(StandardTypes.INTEGER)
public static long fromBigEndian32(@SqlType(StandardTypes.VARBINARY) Slice slice)
{
if (slice.length() != Integer.BYTES) {
throw new PrestoException(INVALID_FUNCTION_ARGUMENT, "expected 4-byte input, but got instead: " + slice.length());
}
return Integer.reverseBytes(slice.getInt(0));
}
代码示例来源:origin: prestodb/presto
@Description("compute SpookyHashV2 32-bit hash")
@ScalarFunction
@SqlType(StandardTypes.VARBINARY)
public static Slice spookyHashV2_32(@SqlType(StandardTypes.VARBINARY) Slice slice)
{
Slice hash = Slices.allocate(Integer.BYTES);
hash.setInt(0, Integer.reverseBytes(SpookyHashV2.hash32(slice, 0, slice.length(), 0)));
return hash;
}
内容来源于网络,如有侵权,请联系作者删除!