We're at little-endian only
authorCryptoManiac <balthazar.ad@gmail.com>
Thu, 20 Aug 2015 08:39:52 +0000 (11:39 +0300)
committerCryptoManiac <balthazar.ad@gmail.com>
Thu, 20 Aug 2015 08:39:52 +0000 (11:39 +0300)
Novacoin/CBlock.cs
Novacoin/CBlockHeader.cs
Novacoin/CTransaction.cs
Novacoin/CTxIn.cs
Novacoin/CTxOut.cs
Novacoin/Hash.cs
Novacoin/Interop.cs
Novacoin/VarInt.cs

index 4402480..68e813a 100644 (file)
@@ -35,12 +35,12 @@ namespace Novacoin
             WrappedList<byte> wBytes = new WrappedList<byte>(blockBytes);
 
             // Fill the block header fields
-            header.nVersion = Interop.LEBytesToUInt32(wBytes.GetItems(4));
+            header.nVersion = BitConverter.ToUInt32(wBytes.GetItems(4), 0);
             header.prevHash = new Hash256(wBytes.GetItems(32));
             header.merkleRoot = new Hash256(wBytes.GetItems(32));
-            header.nTime = Interop.LEBytesToUInt32(wBytes.GetItems(4));
-            header.nBits = Interop.LEBytesToUInt32(wBytes.GetItems(4));
-            header.nNonce = Interop.LEBytesToUInt32(wBytes.GetItems(4));
+            header.nTime = BitConverter.ToUInt32(wBytes.GetItems(4), 0);
+            header.nBits = BitConverter.ToUInt32(wBytes.GetItems(4), 0);
+            header.nNonce = BitConverter.ToUInt32(wBytes.GetItems(4), 0);
 
             // Parse transactions list
             vtx = CTransaction.ReadTransactionsList(ref wBytes);
index b3b18c3..1eb4885 100644 (file)
@@ -54,12 +54,12 @@ namespace Novacoin
         {
             List<byte> r = new List<byte>();
 
-            r.AddRange(Interop.LEBytes(nVersion));
+            r.AddRange(BitConverter.GetBytes(nVersion));
             r.AddRange(prevHash.hashBytes);
             r.AddRange(merkleRoot.hashBytes);
-            r.AddRange(Interop.LEBytes(nTime));
-            r.AddRange(Interop.LEBytes(nBits));
-            r.AddRange(Interop.LEBytes(nNonce));
+            r.AddRange(BitConverter.GetBytes(nTime));
+            r.AddRange(BitConverter.GetBytes(nBits));
+            r.AddRange(BitConverter.GetBytes(nNonce));
 
             return r;
         }
index 9ed33ca..6647c11 100644 (file)
@@ -49,8 +49,8 @@ namespace Novacoin
                {
             WrappedList<byte> wBytes = new WrappedList<byte>(txBytes);
 
-            nVersion = Interop.LEBytesToUInt32(wBytes.GetItems(4));
-            nTime = Interop.LEBytesToUInt32(wBytes.GetItems(4));
+            nVersion = BitConverter.ToUInt32(wBytes.GetItems(4),0);
+            nTime = BitConverter.ToUInt32(wBytes.GetItems(4),0);
 
             int nInputs = (int)VarInt.ReadVarInt(ref wBytes);
             vin = new CTxIn[nInputs];
@@ -61,9 +61,9 @@ namespace Novacoin
                 vin[nCurrentInput] = new CTxIn();
 
                 vin[nCurrentInput].txID = new Hash256(wBytes.GetItems(32));
-                vin[nCurrentInput].n = Interop.LEBytesToUInt32(wBytes.GetItems(4));
+                vin[nCurrentInput].n = BitConverter.ToUInt32(wBytes.GetItems(4),0);
                 vin[nCurrentInput].scriptSig = wBytes.GetItems((int)VarInt.ReadVarInt(ref wBytes));
-                vin[nCurrentInput].nSequence = Interop.LEBytesToUInt32(wBytes.GetItems(4));
+                vin[nCurrentInput].nSequence = BitConverter.ToUInt32(wBytes.GetItems(4),0);
             }
 
             int nOutputs = (int)VarInt.ReadVarInt(ref wBytes);
@@ -73,11 +73,11 @@ namespace Novacoin
             {
                 // Fill outputs array
                 vout[nCurrentOutput] = new CTxOut();
-                vout[nCurrentOutput].nValue = Interop.LEBytesToUInt64(wBytes.GetItems(8));
+                vout[nCurrentOutput].nValue = BitConverter.ToUInt64(wBytes.GetItems(8),0);
                 vout[nCurrentOutput].scriptPubKey = wBytes.GetItems((int)VarInt.ReadVarInt(ref wBytes));
             }
 
-            nLockTime = Interop.LEBytesToUInt32(wBytes.GetItems(4));
+            nLockTime = BitConverter.ToUInt32(wBytes.GetItems(4), 0);
                }
 
         /// <summary>
@@ -98,8 +98,8 @@ namespace Novacoin
                 // Fill the transactions array
                 tx[nTx] = new CTransaction();
 
-                tx[nTx].nVersion = Interop.LEBytesToUInt32(wTxBytes.GetItems(4));
-                tx[nTx].nTime = Interop.LEBytesToUInt32(wTxBytes.GetItems(4));
+                tx[nTx].nVersion = BitConverter.ToUInt32(wTxBytes.GetItems(4), 0);
+                tx[nTx].nTime = BitConverter.ToUInt32(wTxBytes.GetItems(4), 0);
 
                 // Inputs array
                 tx[nTx].vin = CTxIn.ReadTxInList(ref wTxBytes);
@@ -107,7 +107,7 @@ namespace Novacoin
                 // outputs array
                 tx[nTx].vout = CTxOut.ReadTxOutList(ref wTxBytes);
 
-                tx[nTx].nLockTime = Interop.LEBytesToUInt32(wTxBytes.GetItems(4));
+                tx[nTx].nLockTime = BitConverter.ToUInt32(wTxBytes.GetItems(4), 0);
             }
 
             return tx;
@@ -161,8 +161,8 @@ namespace Novacoin
             // 76a91408c8768d5d6bf7c1d9609da4e766c3f1752247b188ac -- scriptPubKey
             // 00000000 -- lock time
 
-            resultBytes.AddRange(Interop.LEBytes(nVersion));
-            resultBytes.AddRange(Interop.LEBytes(nTime));
+            resultBytes.AddRange(BitConverter.GetBytes(nVersion));
+            resultBytes.AddRange(BitConverter.GetBytes(nTime));
             resultBytes.AddRange(VarInt.EncodeVarInt(vin.LongLength));
 
             foreach(CTxIn input in vin)
@@ -177,7 +177,7 @@ namespace Novacoin
                 resultBytes.AddRange(output.ToBytes());
             }
 
-            resultBytes.AddRange(Interop.LEBytes(nLockTime));
+            resultBytes.AddRange(BitConverter.GetBytes(nLockTime));
 
             return resultBytes;
         }
index bc6850a..f5fbc77 100644 (file)
@@ -67,9 +67,9 @@ namespace Novacoin
                 vin[nIndex] = new CTxIn();
 
                 vin[nIndex].txID = new Hash256(wBytes.GetItems(32));
-                vin[nIndex].n = Interop.LEBytesToUInt32(wBytes.GetItems(4));
+                vin[nIndex].n = BitConverter.ToUInt32(wBytes.GetItems(4), 0);
                 vin[nIndex].scriptSig = wBytes.GetItems((int)VarInt.ReadVarInt(ref wBytes));
-                vin[nIndex].nSequence = Interop.LEBytesToUInt32(wBytes.GetItems(4));
+                vin[nIndex].nSequence = BitConverter.ToUInt32(wBytes.GetItems(4), 0);
             }
 
             // Return inputs array
@@ -85,10 +85,10 @@ namespace Novacoin
             List<byte> inputBytes = new List<byte>();
 
             inputBytes.AddRange(txID.hashBytes); // Input transaction id
-            inputBytes.AddRange(Interop.LEBytes(n)); // Output number
+            inputBytes.AddRange(BitConverter.GetBytes(n)); // Output number
             inputBytes.AddRange(VarInt.EncodeVarInt(scriptSig.LongLength)); // scriptSig length
             inputBytes.AddRange(scriptSig); // scriptSig
-            inputBytes.AddRange(Interop.LEBytes(nSequence)); // Sequence
+            inputBytes.AddRange(BitConverter.GetBytes(nSequence)); // Sequence
 
             return inputBytes;
         }
index 4f88955..94a853c 100644 (file)
@@ -50,7 +50,7 @@ namespace Novacoin
             {
                 // Fill outputs array
                 vout[nIndex] = new CTxOut();
-                vout[nIndex].nValue = Interop.LEBytesToUInt64(wBytes.GetItems(8));
+                vout[nIndex].nValue = BitConverter.ToUInt32(wBytes.GetItems(8), 0);
                 vout[nIndex].scriptPubKey = wBytes.GetItems((int)VarInt.ReadVarInt(ref wBytes));
             }
 
@@ -65,7 +65,7 @@ namespace Novacoin
         {
             List<byte> resultBytes = new List<byte>();
 
-            resultBytes.AddRange(Interop.LEBytes(nValue)); // txout value
+            resultBytes.AddRange(BitConverter.GetBytes(nValue)); // txout value
             resultBytes.AddRange(VarInt.EncodeVarInt(scriptPubKey.LongLength)); // scriptPubKey length
             resultBytes.AddRange(scriptPubKey); // scriptPubKey
 
index 1d23fec..87fe573 100644 (file)
@@ -59,7 +59,7 @@ namespace Novacoin
 
         public override string ToString()
         {
-            return Interop.ToHex(Interop.ReverseIfLE(_hashBytes));
+            return Interop.ToHex(Interop.ReverseBytes(_hashBytes));
         }
     }
 }
index 3bae5e0..1f9f0de 100644 (file)
@@ -24,108 +24,34 @@ namespace Novacoin
 
     public class Interop
     {
-        public static byte[] ReverseIfLE(byte[] source)
+        public static byte[] ReverseBytes(byte[] source)
         {
-            if (BitConverter.IsLittleEndian)
-            {
-                Array.Reverse(source);
-            }
+            Array.Reverse(source);
 
             return source;
         }
 
         public static byte[] LEBytes(uint[] values)
         {
-            if (BitConverter.IsLittleEndian)
-            {
-                byte[] result = new byte[values.Length * sizeof(uint)];
-                Buffer.BlockCopy(values, 0, result, 0, result.Length);
-
-                return result;
-            }
-            else
-            {
-                List<byte> result = new List<byte>();
-
-                foreach (uint i in values)
-                {
-                    result.AddRange(LEBytes(i));
-                }
+            byte[] result = new byte[values.Length * sizeof(uint)];
+            Buffer.BlockCopy(values, 0, result, 0, result.Length);
 
-                return result.ToArray();
-            }
+            return result;
         }
 
         public static uint[] ToUInt32Array(byte[] bytes)
         {
-            if (BitConverter.IsLittleEndian)
-            {
-                uint[] result = new uint[bytes.Length / sizeof(uint)];
-                Buffer.BlockCopy(bytes, 0, result, 0, bytes.Length);
-
-                return result;
-            }
-            else
-            {
-                List<uint> result = new List<uint>();
-
-                for (int i = 0; i < bytes.Length; i += 4)
-                {
-                    result.Add(LEBytesToUInt32(bytes.Skip(i).Take(4).ToArray()));
-                }
-
-                return result.ToArray();
-            }
-        }
-
-        public static byte[] LEBytes(ushort n)
-        {
-            byte[] resultBytes = BitConverter.GetBytes(n);
-
-            if (!BitConverter.IsLittleEndian)
-            {
-                // Reverse array if we are on big-endian machine
-                Array.Reverse(resultBytes);
-            }
-
-            return resultBytes;
-        }
-
-        public static byte[] LEBytes(uint n)
-        {
-            byte[] resultBytes = BitConverter.GetBytes(n);
-
-            if (!BitConverter.IsLittleEndian)
-            {
-                // Reverse array if we are on big-endian machine
-                Array.Reverse(resultBytes);
-            }
+            uint[] result = new uint[bytes.Length / sizeof(uint)];
+            Buffer.BlockCopy(bytes, 0, result, 0, bytes.Length);
 
-            return resultBytes;
-        }
-
-        public static byte[] LEBytes(ulong n)
-        {
-            byte[] resultBytes = BitConverter.GetBytes(n);
-
-            if (!BitConverter.IsLittleEndian)
-            {
-                // Reverse array if we are on big-endian machine
-                Array.Reverse(resultBytes);
-            }
-
-            return resultBytes;
+            return result;
         }
 
         public static byte[] BEBytes(ushort n)
         {
             byte[] resultBytes = BitConverter.GetBytes(n);
 
-            if (BitConverter.IsLittleEndian)
-            {
-                // Reverse array if we are on little-endian machine
-                Array.Reverse(resultBytes);
-            }
+            Array.Reverse(resultBytes);
 
             return resultBytes;
         }
@@ -134,11 +60,7 @@ namespace Novacoin
         {
             byte[] resultBytes = BitConverter.GetBytes(n);
 
-            if (BitConverter.IsLittleEndian)
-            {
-                // Reverse array if we are on little-endian machine
-                Array.Reverse(resultBytes);
-            }
+            Array.Reverse(resultBytes);
 
             return resultBytes;
         }
@@ -147,62 +69,11 @@ namespace Novacoin
         {
             byte[] resultBytes = BitConverter.GetBytes(n);
 
-            if (BitConverter.IsLittleEndian)
-            {
-                // Reverse array if we are on little-endian machine
-                Array.Reverse(resultBytes);
-            }
+            Array.Reverse(resultBytes);
 
             return resultBytes;
         }
 
-        public static ushort LEBytesToUInt16(byte[] bytes)
-        {
-            if (bytes.Length != sizeof(ushort))
-            {
-                throw new InteropException("Array size doesn't match the ushort data type.");
-            }
-
-            if (!BitConverter.IsLittleEndian)
-            {
-                // Reverse array if we are on big-endian machine
-                Array.Reverse(bytes);
-            }
-
-            return BitConverter.ToUInt16(bytes, 0);
-        }
-
-        public static uint LEBytesToUInt32(byte[] bytes)
-        {
-            if (bytes.Length != sizeof(uint))
-            {
-                throw new InteropException("Array size doesn't match the uint data type.");
-            }
-
-            if (!BitConverter.IsLittleEndian)
-            {
-                // Reverse array if we are on big-endian machine
-                Array.Reverse(bytes);
-            }
-
-            return BitConverter.ToUInt32(bytes, 0);
-        }
-
-        public static ulong LEBytesToUInt64(byte[] bytes)
-        {
-            if (bytes.Length != sizeof(ulong))
-            {
-                throw new InteropException("Array size doesn't match the ulong data type.");
-            }
-
-            if (!BitConverter.IsLittleEndian)
-            {
-                // Reverse array if we are on big-endian machine
-                Array.Reverse(bytes);
-            }
-
-            return BitConverter.ToUInt64(bytes, 0);
-        }
 
         public static ushort BEBytesToUInt16(byte[] bytes)
         {
@@ -211,11 +82,7 @@ namespace Novacoin
                 throw new InteropException("Array size doesn't match the ushort data type.");
             }
 
-            if (BitConverter.IsLittleEndian)
-            {
-                // Reverse array if we are on little-endian machine
-                Array.Reverse(bytes);
-            }
+            Array.Reverse(bytes);
 
             return BitConverter.ToUInt16(bytes, 0);
         }
@@ -227,11 +94,7 @@ namespace Novacoin
                 throw new InteropException("Array size doesn't match the uint data type.");
             }
 
-            if (BitConverter.IsLittleEndian)
-            {
-                // Reverse array if we are on little-endian machine
-                Array.Reverse(bytes);
-            }
+            Array.Reverse(bytes);
 
             return BitConverter.ToUInt32(bytes, 0);
         }
@@ -243,11 +106,7 @@ namespace Novacoin
                 throw new InteropException("Array size doesn't match the ulong data type.");
             }
 
-            if (BitConverter.IsLittleEndian)
-            {
-                // Reverse array if we are on little-endian machine
-                Array.Reverse(bytes);
-            }
+            Array.Reverse(bytes);
 
             return BitConverter.ToUInt64(bytes, 0);
         }
@@ -268,172 +127,5 @@ namespace Novacoin
             }
             return sb.ToString();
         }
-
-        public static void UInt16ToBE(ushort n, byte[] bs)
-        {
-            bs[0] = (byte)(n >> 8);
-            bs[1] = (byte)(n);
-        }
-
-        public static ushort BEToUInt16(byte[] bs)
-        {
-            ushort n = (ushort)(bs[0] << 8);
-            n |= (ushort)bs[1];
-            return n;
-        }
-
-        public static ushort BEToUInt16(byte[] bs, int off)
-        {
-            ushort n = (ushort)(bs[off] << 8);
-            n |= (ushort)bs[++off];
-            return n;
-        }
-
-        public static void UInt16ToLE(ushort n, byte[] bs)
-        {
-            bs[0] = (byte)(n);
-            bs[1] = (byte)(n >> 8);
-        }
-
-        public static void UInt16ToLE(ushort n, byte[] bs, int off)
-        {
-            bs[off] = (byte)(n);
-            bs[++off] = (byte)(n >> 8);
-        }
-
-        public static ushort LEToUInt16(byte[] bs)
-        {
-            ushort n = (ushort)bs[0];
-            n |= (ushort)(bs[1] << 8);
-            return n;
-        }
-
-        public static ushort LEToUInt16(byte[] bs, int off)
-        {
-            ushort n = (ushort)bs[off];
-            n |= (ushort)(bs[++off] << 8);
-            return n;
-        }
-
-        public static void UInt32ToBE(uint n, byte[] bs)
-        {
-            bs[0] = (byte)(n >> 24);
-            bs[1] = (byte)(n >> 16);
-            bs[2] = (byte)(n >> 8);
-            bs[3] = (byte)(n);
-        }
-
-        public static void UInt32ToBE(uint n, byte[] bs, int off)
-        {
-            bs[off] = (byte)(n >> 24);
-            bs[++off] = (byte)(n >> 16);
-            bs[++off] = (byte)(n >> 8);
-            bs[++off] = (byte)(n);
-        }
-
-        public static uint BEToUInt32(byte[] bs)
-        {
-            uint n = (uint)bs[0] << 24;
-            n |= (uint)bs[1] << 16;
-            n |= (uint)bs[2] << 8;
-            n |= (uint)bs[3];
-            return n;
-        }
-
-        public static uint BEToUInt32(byte[] bs, int off)
-        {
-            uint n = (uint)bs[off] << 24;
-            n |= (uint)bs[++off] << 16;
-            n |= (uint)bs[++off] << 8;
-            n |= (uint)bs[++off];
-            return n;
-        }
-
-        public static ulong BEToUInt64(byte[] bs)
-        {
-            uint hi = BEToUInt32(bs);
-            uint lo = BEToUInt32(bs, 4);
-            return ((ulong)hi << 32) | (ulong)lo;
-        }
-
-        public static ulong BEToUInt64(byte[] bs, int off)
-        {
-            uint hi = BEToUInt32(bs, off);
-            uint lo = BEToUInt32(bs, off + 4);
-            return ((ulong)hi << 32) | (ulong)lo;
-        }
-
-        public static void UInt64ToBE(ulong n, byte[] bs)
-        {
-            UInt32ToBE((uint)(n >> 32), bs);
-            UInt32ToBE((uint)(n), bs, 4);
-        }
-
-        public static void UInt64ToBE(ulong n, byte[] bs, int off)
-        {
-            UInt32ToBE((uint)(n >> 32), bs, off);
-            UInt32ToBE((uint)(n), bs, off + 4);
-        }
-
-        public static void UInt32ToLE(uint n, byte[] bs)
-        {
-            bs[0] = (byte)(n);
-            bs[1] = (byte)(n >> 8);
-            bs[2] = (byte)(n >> 16);
-            bs[3] = (byte)(n >> 24);
-        }
-
-        public static void UInt32ToLE(uint n, byte[] bs, int off)
-        {
-            bs[off] = (byte)(n);
-            bs[++off] = (byte)(n >> 8);
-            bs[++off] = (byte)(n >> 16);
-            bs[++off] = (byte)(n >> 24);
-        }
-
-        public static uint LEToUInt32(byte[] bs)
-        {
-            uint n = (uint)bs[0];
-            n |= (uint)bs[1] << 8;
-            n |= (uint)bs[2] << 16;
-            n |= (uint)bs[3] << 24;
-            return n;
-        }
-
-        public static uint LEToUInt32(byte[] bs, int off)
-        {
-            uint n = (uint)bs[off];
-            n |= (uint)bs[++off] << 8;
-            n |= (uint)bs[++off] << 16;
-            n |= (uint)bs[++off] << 24;
-            return n;
-        }
-
-        public static ulong LEToUInt64(byte[] bs)
-        {
-            uint lo = LEToUInt32(bs);
-            uint hi = LEToUInt32(bs, 4);
-            return ((ulong)hi << 32) | (ulong)lo;
-        }
-
-        public static ulong LEToUInt64(byte[] bs, int off)
-        {
-            uint lo = LEToUInt32(bs, off);
-            uint hi = LEToUInt32(bs, off + 4);
-            return ((ulong)hi << 32) | (ulong)lo;
-        }
-
-        public static void UInt64ToLE(ulong n, byte[] bs)
-        {
-            UInt32ToLE((uint)(n), bs);
-            UInt32ToLE((uint)(n >> 32), bs, 4);
-        }
-
-        public static void UInt64ToLE(ulong n, byte[] bs, int off)
-        {
-            UInt32ToLE((uint)(n), bs, off);
-            UInt32ToLE((uint)(n >> 32), bs, off + 4);
-        }
-
     }
 }
index 42041c0..5fa2685 100644 (file)
@@ -33,19 +33,19 @@ namespace Novacoin
                 {
                     // ushort flag
                     prefix = 0xfd;
-                    valueBytes = Interop.LEBytes((ushort)n);
+                    valueBytes = BitConverter.GetBytes((ushort)n);
                 }
                 else if (n <= uint.MaxValue)
                 {
                     // uint flag
                     prefix = 0xfe;
-                    valueBytes = Interop.LEBytes((uint)n);
+                    valueBytes = BitConverter.GetBytes((uint)n);
                 }
                 else
                 {
                     // ulong flag
                     prefix = 0xff;
-                    valueBytes = Interop.LEBytes(n);
+                    valueBytes = BitConverter.GetBytes(n);
                 }
 
                 resultBytes.Add(prefix);
@@ -82,40 +82,16 @@ namespace Novacoin
 
             byte[] bytesArray = bytes.ToArray();
 
-            if (BitConverter.IsLittleEndian)
-            {
-                switch (prefix)
-                {
-                    case 0xfd: // ushort flag
-                        return BitConverter.ToUInt16(bytesArray, 0);
-                    case 0xfe: // uint flag
-                        return BitConverter.ToUInt32(bytesArray, 0);
-                    case 0xff: // ulong flag
-                        return BitConverter.ToUInt64(bytesArray, 0);
-                    default:
-                        return prefix;
-                }
-            }
-            else
+            switch (prefix)
             {
-                // Values are stored in little-endian order
-                switch (prefix)
-                {
-                    case 0xfd: // ushort flag
-                        Array.Resize(ref bytesArray, 2);
-                        Array.Reverse(bytesArray);
-                        return BitConverter.ToUInt16(bytesArray, 0);
-                    case 0xfe: // uint flag
-                        Array.Resize(ref bytesArray, 4);
-                        Array.Reverse(bytesArray);
-                        return BitConverter.ToUInt32(bytesArray, 0);
-                    case 0xff: // ulong flag
-                        Array.Resize(ref bytesArray, 8);
-                        Array.Reverse(bytesArray);
-                        return BitConverter.ToUInt64(bytesArray, 0);
-                    default:
-                        return prefix;
-                }
+                case 0xfd: // ushort flag
+                    return BitConverter.ToUInt16(bytesArray, 0);
+                case 0xfe: // uint flag
+                    return BitConverter.ToUInt32(bytesArray, 0);
+                case 0xff: // ulong flag
+                    return BitConverter.ToUInt64(bytesArray, 0);
+                default:
+                    return prefix;
             }
         }
 
@@ -133,11 +109,11 @@ namespace Novacoin
             switch (prefix)
             {
                 case 0xfd: // ushort
-                    return Interop.LEBytesToUInt16(wBytes.GetItems(2));
+                    return BitConverter.ToUInt16(wBytes.GetItems(2), 0);
                 case 0xfe: // uint
-                    return Interop.LEBytesToUInt32(wBytes.GetItems(4));
+                    return BitConverter.ToUInt32(wBytes.GetItems(4), 0);
                 case 0xff: // ulong
-                    return Interop.LEBytesToUInt64(wBytes.GetItems(8));
+                    return BitConverter.ToUInt64(wBytes.GetItems(8), 0);
                 default:
                     return prefix;
             }