Solved

vb.net hex to file

Posted on 2009-04-10
5
287 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
Comment Utility
You should be able to do this:

Dim byteData As Byte = 11

0
 
LVL 1

Author Comment

by:03671328
Comment Utility
tryed that comes back as 0B
0
 
LVL 96

Expert Comment

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

Author Comment

by:03671328
Comment Utility
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
Comment Utility
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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

772 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now