Little endian to big endian in Groovy 2.0?

What is the best way to convert a small endian to a large endian?

def i = 0x12345678; def j = 0x78563412; assert i == convert(j) // ? 

I know that I can mask bytes and reorder them, but what is a more attractive way?

+4
source share
1 answer

Good ol 'Java (SE5 +):

 assert i == Integer.reverseBytes(j) 

but Groovier:

 def convert = Integer.&reverseBytes assert i == convert(j) 
+8
source

Source: https://habr.com/ru/post/1488954/


All Articles