Results 1 to 11 of 11

Thread: Hex -> Integer, How to

  1. #1

    Thread Starter
    Hyperactive Member Q_Me's Avatar
    Join Date
    Dec 2001
    Posts
    327

    Question Hex -> Integer, How to

    How do I convert Hex to an Integer?
    53323737 15 743 313402 05 740313063. 17 15 4150 743 313402 05 140393403437 5203 743 30210.


  2. #2
    So Unbanned DiGiTaIErRoR's Avatar
    Join Date
    Apr 1999
    Location
    /dev/null
    Posts
    4,111
    val("&HFF") = 255

    so val("&h" & hex_val)

  3. #3

    Thread Starter
    Hyperactive Member Q_Me's Avatar
    Join Date
    Dec 2001
    Posts
    327
    You missed the point DigitalError. The thing i'm trying to find is:

    VB Code:
    1. Function ConvertHex(Input as String) as Integer
    2.  
    3. Output = Something(Input)
    4. ConvertHex = Output
    5.  
    6. End Function
    53323737 15 743 313402 05 740313063. 17 15 4150 743 313402 05 140393403437 5203 743 30210.


  4. #4
    PowerPoster
    Join Date
    Aug 2000
    Location
    India
    Posts
    2,288
    If you are sure that conversion will remain within Integer bounds, then use the CInt function, otherwise use the CLng function.

  5. #5

    Thread Starter
    Hyperactive Member Q_Me's Avatar
    Join Date
    Dec 2001
    Posts
    327
    Those functions do not work with STRING type Hex.

    The hex I am using is not the "&H??" its more like a string type.
    eg.

    VB Code:
    1. i = ConvertHex("FF")
    2. 'i = 255
    53323737 15 743 313402 05 740313063. 17 15 4150 743 313402 05 140393403437 5203 743 30210.


  6. #6
    PowerPoster
    Join Date
    Aug 2000
    Location
    India
    Posts
    2,288
    Why don't you append the &H at the begining?
    VB Code:
    1. Private Function ConvertHex(ByRef HexValue As String) As Long
    2.     If Not UCase(Left$(HexValue, 2)) = "H&" Then HexValue = "&H" & HexValue
    3.     ConvertHex = CLng(HexValue)
    4. End Function

  7. #7

    Thread Starter
    Hyperactive Member Q_Me's Avatar
    Join Date
    Dec 2001
    Posts
    327
    Because wrighting filenames.

    eg.

    Filename.002
    Filename.0BF

    VB Code:
    1. 'ID = 0 to 4096
    2. iHex = ConvertToHex(ID)
    3. OpenAsTextStream(Filename & iHex, blah, blah) 'iHex = number after conversion from i
    4.  
    5. 'Then:
    6. ID=ConvertToI(Right(Filename, 3))
    7. '^^^ this is what i mean.

    Long Story Short. Dont ask why the hell I'm doing this, because it is too hard & long to explain.
    53323737 15 743 313402 05 740313063. 17 15 4150 743 313402 05 140393403437 5203 743 30210.


  8. #8

    Thread Starter
    Hyperactive Member Q_Me's Avatar
    Join Date
    Dec 2001
    Posts
    327
    Here this will help:

    VB Code:
    1. Filename = User_ID.1AF 'Sample File
    2. ID = ConvertToInteger(Right(Filename, 3) 'Converts the"1AF" to an Integer.
    3.  
    4. ID = ?
    53323737 15 743 313402 05 740313063. 17 15 4150 743 313402 05 140393403437 5203 743 30210.


  9. #9
    PowerPoster
    Join Date
    Aug 2000
    Location
    India
    Posts
    2,288
    VB Code:
    1. ID = ConvertToInteger("&H" & Right(Filename, 3)

    And then In ConvertToInteger function use CInt.

  10. #10

    Thread Starter
    Hyperactive Member Q_Me's Avatar
    Join Date
    Dec 2001
    Posts
    327
    I'll post the rest of what the hell I'm doing tomarrow. But that works thanx.
    53323737 15 743 313402 05 740313063. 17 15 4150 743 313402 05 140393403437 5203 743 30210.


  11. #11
    Banned DiGiTalErRoR's Avatar
    Join Date
    Sep 2002
    Posts
    68
    You add the &H in the conversion function, from the's original value.

    Duh.

    here:

    VB Code:
    1. Function HexToInt(byval HexDat as string) as Integer
    2. HexIoInt = val("&h" & HexDat)
    3. End Function

    To use:

    i HexToInt("FF")

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