Convert and saving a Byte array HEX values to binary file
Dear All ,
I have a device with upon serial communication , it send the data as HEX values , (eg, C020042ABD0F91A103E400F929EBC) . I use the following code to get data from the serial port.
Dim fStream As New FileStream(sFileName, FileMode.CreateNew) ' creates new file
Dim bw As New BinaryWriter(fStream)
ComTd.Read(data, 1, bCount)
Dim bCount As Integer = 4119 ' it is the size of the chunk not block size
Dim data(bCount) As Byte
bw.Write(data) ' This saves the byte array to a binary file .
The problem is that the stored data are in hex not decimal . I want to covert this HEX data in the byte array to a decimal to save into binray file .
Thanks for your fast response , but the problem is that I had the bytes in an array. I need to convert each 2 bytes into one HEX . This is because I receive from the device through serial communcation data that are in HEX mode (eg C020042ABD0F91A103E400F929EBC) . Upon receive data from serial port into Byte , the data are transformed into ASCII code for each letter , eg , "C0" is a HEX number , however , the byte read it as C [and converts it to 67 which is the ASCII code for C] and the 0 [and converts it to 48] . I need to first read each 2 bytes [ie C0] , and convert them to the decimal part [which is 192] , thus when it is saved to binary file , it is read correctly .
Dim fStream As New System.IO.FileStream("c:\asfas", IO.FileMode.Create)
Dim bWriter As New System.IO.BinaryWriter(fStream)
Dim data(4119) As Byte
For i = 0 To UBound(data) Step 2
bWriter.Write(Convert.ToInt32(CStr(Convert.ToChar(data(i))) & CStr(Convert.ToChar(data(i + 1))), 16))
Write a C program that should create a 10 element array of random integers (0 to 9). The program should total all of the numbers in the odd positions of the array and compare them with the total of the numbers in the even positions of the array and indicate ...
I have a 2d matrix with dimension (3, n) called A, I want to calculate the normalization and cross product of two arrays (b,z) (see the code please) for each column (for the first column, then the second one and so on).
the function that I created to find the ...