Whats the best way to convert a little endian number to a big endian number?
def i = 0x12345678;
def j = 0x78563412;
assert i == convert(j) // ?
I know I could mask the bytes and reorder them but what's a groovier way?
Good ol' Java (SE5+):
assert i == Integer.reverseBytes(j)
but Groovier:
def convert = Integer.&reverseBytes
assert i == convert(j)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With