Assets/Scripts/BIP39/Utilities.cs
/// <summary>
/// This switches the Endianess of the provided byte array, byte per byte we do bit swappy.
/// </summary>
/// <param name="bytes">Bytes to change endianess of</param>
/// <returns>Bytes with endianess swapped</returns>
This switches the Endianess of the provided byte array, byte per byte we do bit swappy.
This switches the Endianess of the provided byte array byte per byte we do bit swappy .
public static byte[] SwapEndianBytes(byte[] bytes)
        {
            byte[] output = new byte[bytes.Length];
            int index = 0;
            foreach (byte b in bytes)
            {
                byte[] ba = { b };
                BitArray bits = new BitArray(ba);
                int newByte = 0;
                if (bits.Get(7)) newByte++;
                if (bits.Get(6)) newByte += 2;
                if (bits.Get(5)) newByte += 4;
                if (bits.Get(4)) newByte += 8;
                if (bits.Get(3)) newByte += 16;
                if (bits.Get(2)) newByte += 32;
                if (bits.Get(1)) newByte += 64;
                if (bits.Get(0)) newByte += 128;
                output[index] = Convert.ToByte(newByte);
                index++;
            }
            return output;
        }
public static byte [ ] SwapEndianBytes ( byte [ ] bytes ) { byte [ ] output = new byte [ bytes . Length ] ; int index = 0 ; foreach ( byte b in bytes ) { byte [ ] ba = { b } ; BitArray bits = new BitArray ( ba ) ; int newByte = 0 ; if ( bits . Get ( 7 ) ) newByte ++ ; if ( bits . Get ( 6 ) ) newByte += 2 ; if ( bits . Get ( 5 ) ) newByte += 4 ; if ( bits . Get ( 4 ) ) newByte += 8 ; if ( bits . Get ( 3 ) ) newByte += 16 ; if ( bits . Get ( 2 ) ) newByte += 32 ; if ( bits . Get ( 1 ) ) newByte += 64 ; if ( bits . Get ( 0 ) ) newByte += 128 ; output [ index ] = Convert . ToByte ( newByte ) ; index ++ ; } return output ; }
This switches the Endianess of the provided byte array, byte per byte we do bit swappy.
This switches the Endianess of the provided byte array byte per byte we do bit swappy .
//I love lamp
Bytes with endianess swapped
Bytes with endianess swapped
bytes
byte[]
Bytes to change endianess of
Bytes to change endianess of