I am building a client application which needs to send packet to server in a particular format such that if the byte is 0xA3, the server expects it as {0x3A, 0x33}
I had used the below approach earlier. It works well if the byte is for instance 0x89. But if the byte is 0xA3 it doesnt work
string hex = hexStr .Length == 1 ? "0" + hexStr:hexStr ;
byte packet1 = (byte)(int.Parse(hex[0].ToString(), System.Globalization.NumberStyles.HexNumber) + 0x30);
byte packet2 = (byte)(int.Parse(hex[1].ToString(), System.Globalization.NumberStyles.HexNumber) + 0x30);
Examples of expected output
- input => 0x89 , Output => {0x38, 0x39}
- input => 0xA3 , Output => {0x3A, 0x33}
However if i use the above code i get the following output
- input => 0x89 , Output => {0x38, 0x39}
- input => 0xA3 , Output => {0x41, 0x33}
byte.Parse... and if it doesn't work, please tell us which cases it doesn't work for...