'Mac Address Dim Mac(5) As Byte Dim i As Integer For i = 0 To Row.MacAddress.Length - 1 Step 2 Mac(CType(i / 2, Int32)) = Convert.ToByte(Row.MacAddress.Substring(i, 2), 16) Next Row.MacAddrBin = Mac
/// <summary> /// Convert string to byte_array /// </summary> /// <param name="strInput"> private byte[] String_To_Bytes(string strInput) { // i variable used to hold position in string int i = 0; // x variable used to hold byte array element position int x = 0; // allocate byte array based on half of string length byte[] bytes = new byte[(strInput.Length) / 2]; // loop through the string - 2 bytes at a time converting // it to decimal equivalent and store in byte array while (strInput.Length > i + 1) { long lngDecimal = Convert.ToInt32(strInput.Substring(i, 2), 16); bytes[x] = Convert.ToByte(lngDecimal); i = i + 2; ++x; } // return the finished byte array of decimal values return bytes; } /// <summary> /// Convert byte_array to string /// </summary> /// <param name="bytes_Input"> private string Bytes_To_String(byte[] bytes_Input) { // convert the byte array back to a true string string strTemp = ""; for (int x = 0; x <= bytes_Input.GetUpperBound(0); x++) { int number = int.Parse(bytes_Input[x].ToString()); strTemp += number.ToString("X").PadLeft(2, '0'); } // return the finished string of hex values return strTemp; }