Solved

vb.net hex to file

Posted on 2009-04-10
5
294 Views
Last Modified: 2013-11-26
im trying to convert in vb.net

10 43 74 98 F0 9A 7D CB C1 FA 7A A1 01 FE 97 6E
40 30 0D 06 09 2A 86 48 86 F7 0D 01 01 05 05 00 ect

what do i need to do to take 10 and wite that to file ...

the code below will not work as exptected ...
if i toss in the 00 it will write 00 but if i toss in 11 it will write 0B
any ideas how to fix this problem

thanks in advance.
Dim byteData As Byte = Byte.Parse("00")
Dim oFileStream As System.IO.FileStream
oFileStream = New System.IO.FileStream("bytes.dat", System.IO.FileMode.Append)
oFileStream.WriteByte(byteData)
oFileStream.Close()

Open in new window

0
Comment
Question by:03671328
  • 3
  • 2
5 Comments
 
LVL 96

Expert Comment

by:Bob Learned
ID: 24129737
You should be able to do this:

Dim byteData As Byte = 11

0
 
LVL 1

Author Comment

by:03671328
ID: 24129786
tryed that comes back as 0B
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 24129789
0B (hex) is 11 (decimal), so what are you REALLY trying to do here?
0
 
LVL 1

Author Comment

by:03671328
ID: 24129853
i'm trying to write the hex? to the file
i'm trying to take hex and write exactly that to a file.

if i get a string of 11 20 10 18 11 22 22 34
i want it to write just that.
i can split it up just not sure how to write exactly what is there.
0
 
LVL 96

Accepted Solution

by:
Bob Learned earned 500 total points
ID: 24130039
You need to split those pairs up by space, convert the hexadecimal values to decimal, and then use WriteByte with the decimal value.

Simple approach for hex to decimal:

    Dim n As Integer = CInt("&H" & text)

String split by space:

   Dim s As String = text.Split(" ")
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question