I am decoding a byte array from a derived class to string in the main class.
- I get the original value in the derived class in hex
- Copy all the elements to a different array in the main class
- Decode the elements into strings and assign them to the elements of a new array like in the code
- I am trying to apply
GetString (byte[] bytes, int byteIndex, int byteCount);
- Is there any simpler way to do it?
//Derived class byte:
byte[] msg = new byte[8] { 0x01, 0x08, 0x1A, 0x0B, 0xFF, 0x03, 0x31, 0x2C };
//Main Class
byte[] mainClassArray = new byte[8];
string[] ArrayToStr = new string[6];
Array.Copy(MyClass.msg, 0, mainClassArray, 0, 8);
ArrayToStr[0] = ASCIIEncoding.ASCII.GetString(mainClassArray , 0, 4); //decode first 4 and assign to the 1st element of ArrayToStr
ArrayToStr[1] = ASCIIEncoding.ASCII.GetString(mainClassArray , 4, 4); //decode last 4 and assign to the 2nd element of ArrayToStr
ArrayToStr[2] = ASCIIEncoding.ASCII.GetString(mainClassArray , 0, 4); //decode first 4 and assign to the 3rd element of ArrayToStr
ArrayToStr[3] = ASCIIEncoding.ASCII.GetString(mainClassArray , 4, 4); //decode last 4 and assign to the 4th element of ArrayToStr
ArrayToStr[4] = ASCIIEncoding.ASCII.GetString(mainClassArray , 0, 4); //decode first 4 and assign to the 5th element of ArrayToStr
ArrayToStr[5] = ASCIIEncoding.ASCII.GetString(mainClassArray , 4, 4); //decode last 4 and assign to the 6th element of ArrayToStr