Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Little endian to big endian in Groovy 2.0?

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?

like image 765
Parobay Avatar asked Feb 17 '23 01:02

Parobay


1 Answers

Good ol' Java (SE5+):

assert i == Integer.reverseBytes(j)

but Groovier:

def convert = Integer.&reverseBytes
assert i == convert(j)
like image 159
emesx Avatar answered Mar 11 '23 02:03

emesx