views:

541

answers:

5

Hi...

Please guide me how make convert that input to decimal.tq.

BF C2 FF 12 
65 E4 EE 
17 BF C2 64 F2 41 84 11 
C1 C4 38 41 14 10 C1 04 10 49 04 18 41 06 72 B5 FF 
17 BF C2 64 72 
41 84 11 C1 85 19 C1 07 17 7D C2 5F 3D 5E FD DE 57 FD 10 E1 94 30 B5 FF 
17 BF C2 FF 12 
65 CC 76 
17 BF C2 FF 12 
69 FC 77
A: 

Tony, i want using vb.net.tq.

Mohd Rizal
Clarifications should be added in the question (you can edit your own question) or added as a comment to your question. The "answers" section is for answers to your problem. :-)
Heinzi
+1  A: 

If you have Windows open up the calculator and go to view scientific. Then you can convert small pieces of your code one group at a time.

To do it by hand you divide by 16 until you get zero and then you combine the remainders.

Brandon
A: 

Chris J, that data

BF C2 FF 12 65 E4 EE 17 BF C2 64 F2 ....

are hexadecimal?True.Can you comment about space between that data?tq.

Mohd Rizal
The space separates each value. For example FF is different from F. The latter being 15 in base 10 while the former is 255 in base 10 (decimal). Hexadecimal is base 16.
Brandon
To translate 217 for example, it would be 2(16^2) + 1(16^1) + 7(16^0) where ^ n means "raised to the n power".
Brandon
how make converting for each separates values? Pleae suggest suitable vb.net code.
Mohd Rizal
i know how to convert this one by one, but how convert ata large file?
Mohd Rizal
A: 

You should tell us your input and wanted output format. I assumed you have the data in a String variable named "input" and want it as byte array.

Dim input As String = IO.File.ReadAllText("C:\data.txt")
Dim output As Byte() = input.Split(" ").Select(Function(b) Convert.ToByte(b, 16)).ToArray

Edit:

For Each part As String In IO.File.ReadAllText("C:\data.txt").Split(" ")
    If part.Trim.Length > 0 Then
        Dim number As Integer = Convert.ToInt32(part, 16)
        Console.Write(number & ",")
    End If
Next
David R
i have this data at C:\data.txt
Mohd Rizal
Okay fixed that. Output is still Byte() because you said nothing about that.
David R
input at C:\data.txt, and i wat output as console
Mohd Rizal
ouch... output as decimal ,input as byte.tq David R
Mohd Rizal
Function(b) got error .
Mohd Rizal
that error give is "Expression expected"
Mohd Rizal
My guess is you are using a version of VB.NET prior to 2008.I have rewritten the code and it should work now.
David R
i'm using VB.NET 2005 version.thanks David R
Mohd Rizal
If your question is solved now you should flag the answer that best helped you as answer to your question.
David R
i will trying tomorrow.
Mohd Rizal
i vote for second solution, but it's still get error unhandled exception.I'm using vb.net 2005 .I need change to 2008 version or not?
Mohd Rizal
How open port such as COM1,COM2,COM3 or COM4?That data than convert from hex to decimal and showed using console.writeline?
Mohd Rizal
Unhandled Exception is not enough information. You need to help us helping you. Long time since I last used 2005. You should update if possible. I have rewritten the code with less advanced features compatible with old versions.regarding COM you should open a new question cause that has nothing to do with convert byte/decimal.
David R
i will update to 2008 soon.Thank You David R
Mohd Rizal
A: 
Dim input As String = "BF C2 FF 12 65 E4 EE 17 BF C2 64 [...]"
For Each s As String In input.Split(" "c)
    Dim value As Integer = Convert.ToInt32(s, 16)
    Console.Write(value & " ")    ' Or whatever else you want to do with the converted data
Next
Heinzi
what type of c? integer or char?
Mohd Rizal
I don't understand your question. `" "c` means: space character (`' '` in C#), as opposed to `" "`, which would mean: string containing a space (`" "` in C#).
Heinzi
To clarify: The `c` in `" "c` is not a variable but rather a syntactic element (a *literal type character*), see: http://msdn.microsoft.com/en-us/library/s9cz43ek%28VS.80%29.aspx
Heinzi
Dim value = Convert.ToInt32(s, 16) got unhandled exception message.
Mohd Rizal
Me declared s as Byte.it's ok or not?
Mohd Rizal
Then you have some stuff in your input that is not a hexadecimal number, or you have more separators than just space. Wrap the inner part of the loop into a `Try...Catch` block and output an error message including the `s` that caused the trouble. This will help you find the culprit.
Heinzi
@Mohd: No, `s` is a String. Since you are apparently not using `Option Infer`, I will add some type declaration to my example...
Heinzi
it work now, but got message unhandled exception after console write launch.
Mohd Rizal
Dear Heinzi, i will use Try...Catch for find the error.
Mohd Rizal