Add EndianConverter algorithm (#5751)

This commit is contained in:
Hardik Pawar
2024-10-14 13:09:58 +05:30
committed by GitHub
parent 40f2d0cf8e
commit 5a710ea61f
3 changed files with 47 additions and 0 deletions

View File

@ -0,0 +1,23 @@
package com.thealgorithms.conversions;
/**
* Converts between big-endian and little-endian formats.
* Big-endian is the most significant byte first, while little-endian is the least significant byte first.
* Big-endian to little-endian: 0x12345678 -> 0x78563412
*
* Little-endian to big-endian: 0x12345678 -> 0x78563412
*
* @author Hardvan
*/
public final class EndianConverter {
private EndianConverter() {
}
public static int bigToLittleEndian(int value) {
return Integer.reverseBytes(value);
}
public static int littleToBigEndian(int value) {
return Integer.reverseBytes(value);
}
}