Jump to content

Recommended Posts

Ghost    Ghost

324 posts
657 BF$

How to easily swap or change endianness in Javascript, NodeJS, etc. with one simple function! changeEndianness()

          const changeEndianness = (string) => {
                  const result = [];
                  let len = string.length - 2;
                  while (len >= 0) {
                    result.push(string.substr(len, 2));
                    len -= 2;
                  return result.join('');

You can then use this function with any string to convert its endianness

Example of using function:

var yourstringvar = 'Your string goes here to swap endianness';

var newendian = changeEndianness(yourstringvar);

console.log('Your newly swapped endian string', newendian);


  • Denarius 1

Founder of BlockForums.org - PM me for any help - Join our Discord Server: https://discord.gg/UPpQy3n

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Create New...