From 8333346c43b89ee58f756924f9afc05467df623c Mon Sep 17 00:00:00 2001 From: Michael Olayemi Date: Thu, 13 Jul 2023 01:05:34 +0000 Subject: [PATCH] Does Java read integers in little endian or big endian? (#14381) * Does Java read integers in little endian or big endian? * Does Java read integers in little endian or big endian? --- .../com/baeldung/endianness/Endianness.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 core-java-modules/core-java-numbers-6/src/main/java/com/baeldung/endianness/Endianness.java diff --git a/core-java-modules/core-java-numbers-6/src/main/java/com/baeldung/endianness/Endianness.java b/core-java-modules/core-java-numbers-6/src/main/java/com/baeldung/endianness/Endianness.java new file mode 100644 index 0000000000..b84f301ee8 --- /dev/null +++ b/core-java-modules/core-java-numbers-6/src/main/java/com/baeldung/endianness/Endianness.java @@ -0,0 +1,17 @@ +package com.baeldung.endianness; + +import java.nio.ByteBuffer; + +public class Endianness { + + public static void main(String[] args) { + int value = 123456789; + byte[] bytes = ByteBuffer.allocate(4) + .putInt(value) + .array(); + + for (byte b : bytes) { + System.out.format("0x%x ", b); + } + } +}