That is some terrible code.
xEvOx wrote:
public static string HexToAscii(byte[] hex)
bad method name, nothing is hex unless it is a string holding the hex representation of something. should be ToHexString(byte[] bytes)
xEvOx wrote:
string temp = hex[i].ToString("X"); if (temp.Length == 1) temp = "0" + temp;
use ToString("X2") to always get at least two characters
xEvOx wrote:
string ascii = "";
in /NET all strings use Unicode, not ASCII.
xEvOx wrote:
public static uint BytetoUint(byte[] Data)
another bad method name, it does not convert a byte, in converts a byte array. and a very inefficient way to do things: you have numbers in the byte array, turn them into a string in order to extract a numeric value. One should never do that, just work with the numbers themselves, something like (untested):
public static uint ToUint(byte[] bytes) {
uint result=0;
foreach(byte b in bytes) result=(result<<8) | b;
return result;
}
:~
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that.
[The QA section does it automatically now, I hope we soon get it on regular forums as well]