Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace ConvertByteArray
- {
- public static class ByteUtils
- {
- // By : Ivandro Ismael.
- public static int ConvertByteCharsToInt()
- {
- var b = BitConverter.GetBytes(4);
- byte[] bufferDigits = { Convert.ToByte('4'), Convert.ToByte('5'), Convert.ToByte('0') };
- // Note: Each single byte represent a single digit (radix 10 base)
- // e.g: 450
- // 0x34 = 4, 0x35 = 5; 0x30. (three bytes to present 450)
- byte[] newBuffer = new byte[3];
- Array.Copy(bufferDigits, 0, newBuffer, 0, newBuffer.Length);
- //if (BitConverter.IsLittleEndian)
- //{
- // Array.Reverse(bfr);
- //}
- int mask = ~0x30;
- newBuffer[0] = (byte)(newBuffer[0] & mask);
- newBuffer[1] = (byte)(newBuffer[1] & mask);
- newBuffer[2] = (byte)(newBuffer[2] & mask);
- // convert to decimal places
- int intResult = newBuffer[0] * 100 + newBuffer[1] * 10 + newBuffer[2];
- return intResult;
- }
- }
- }
- // Note: No refact were done!
Add Comment
Please, Sign In to add comment