NodeJS Buffer-read little endian buffer

I have a 256 bit long, but written as a little endian:

<Buffer 21 a2 bc 03 6d 18 2f 11 f5 5a bd 5c b4 32 a2 7b 22 79 7e 53 9b cb 44 5b 0e 00 00 00 00 00 00 00>

      

How do I correctly print it as a hexadeciaml value?

buf.toString('hex')

      

buk.toString('hex').split("").reverse().join(""))

gives 0x00000000000000e0b544bcb935e79722b72a234bc5dba55f11f281d630cb2a12

instead of0x000000000000000e5b44cb9b537e79227ba232b45cbd5af5112f186d03bca221

+3


source to share


1 answer


You can use match

instead split

to get an array of two character groups. Then you can cancel the array and join it.



buf.toString('hex').match(/.{2}/g).reverse().join("")

      

+7


source







All Articles