Jump to content

Recommended Posts

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


Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...