Results 1 to 5 of 5

Thread: Converting Hex ...

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Dec 2004
    Location
    South Africa
    Posts
    26

    Question Converting Hex ...

    Hi

    I have a problem converting hex, the file that you have is a .dat file which contains hex code writing certain values at intervals of every 2 seconds.

    I have used a hex editor to open the file, what I dont understand is how to convert each byte into something meaning like a number(integer) or a letter programatically.

    Eg. the some hex is

    4b 33 55 44 = ?? - this should equal K3UD but how do i convert in vb 6
    07 d4 09 12 = ?? - 2004 i think ???

    I hope I explained well enough!!

  2. #2
    Banned
    Join Date
    Dec 2004
    Posts
    174

    Re: Converting Hex ...

    VB Code:
    1. Private Sub Form_Load()
    2.     a = CLng("&H" + "4b")
    3.     MsgBox Chr$(a)
    4. End Sub
    Last edited by _visual_basic_; Dec 25th, 2004 at 01:29 PM.

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Dec 2004
    Location
    South Africa
    Posts
    26

    Re: Converting Hex ...

    Thanks, that worked great for the K3ud part but how do i get 2004 out of
    07 d4 09 12 ??

    I see that the d4 has 0x00FF next to it on the legend paper any idea what thats about?

  4. #4
    Banned
    Join Date
    Dec 2004
    Posts
    174

    Re: Converting Hex ...

    try this out:

    VB Code:
    1. Option Explicit
    2.  
    3. Public Enum TypeConstants
    4.     TypeHex
    5.     TypeChr
    6. End Enum
    7.  
    8. Private Sub Form_Load()
    9.     Call MsgBox("4b 33 55 44 = " & CHex("4b 33 55 44", TypeChr), vbInformation)
    10.     Call MsgBox("K3UD = " & CHex("K3UD"), vbInformation)
    11. End Sub
    12.  
    13. Public Function CHex(Text As String, Optional CTo As TypeConstants = TypeHex) As String
    14.     'MADE BY _VISUAL_BASIC_
    15.     'please dont remove this credit comment =)
    16.     On Error GoTo ErrCatch:
    17.     Dim I As Long: Let I = vbNull
    18.     Dim L As Long: Let L = LenB(Text)
    19.    
    20.     Select Case CTo
    21.         Case TypeChr
    22.             Do Until I > L
    23.                 Let CHex = CHex & Chr$(CLng("&H" + Mid$(Text, I, 2)))
    24.                
    25.                 Let I = I + 3
    26.             Loop
    27.             Exit Function
    28.            
    29.         Case TypeHex
    30.             Do Until I > L
    31.                 Let CHex = CHex & Hex$(Asc(Mid(Text, I, 1)))
    32.                 If I <= L Then
    33.                     Let CHex = CHex & " "
    34.                 End If
    35.                
    36.                 Let I = I + 1
    37.             Loop
    38.             Exit Function
    39.            
    40.         Case Else
    41.             Call Err.Raise(666, "Tpe As TypeConstants", "Type is Unknown")
    42.             Exit Function
    43.     End Select
    44.    
    45. ErrCatch:
    46. End Function
    Last edited by _visual_basic_; Dec 25th, 2004 at 02:01 PM.

  5. #5

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width