Results 1 to 7 of 7

Thread: Howto: Convert Hex --> Integer in VB?

  1. #1

    Thread Starter
    Member
    Join Date
    Aug 2000
    Posts
    57
    say I had a var
    dim vHex as string
    vHex = "&hhe" 'that's a hex code
    vHextoInt = '?? ChangeHextoIntegerFunction ?? (vHex)
    and I wanted to stuff it into a byte
    dim vByteVar as Byte
    vByteVar = Cbyte(vHextoInt)

    How do I convert the Hex to Int??

  2. #2
    Guru Yonatan's Avatar
    Join Date
    Apr 1999
    Location
    Israel
    Posts
    892

    Talking Just CLng it!

    Use CLng!
    Code:
    lblHex.Caption = CLng("&H12AB") ' Convert hexadecimal "12AB" to an integer
    Simple as that!

  3. #3

    Thread Starter
    Member
    Join Date
    Aug 2000
    Posts
    57

    hmm.. doesn't like that either

    dim vTemp
    vTemp = Clng("&h" & Mid(vKey, lCount * 2 + 1, 2))

    doesn't fly, not even if you declare vTemp as an Integer

    &hhe is a hex code right? or do you need 6 chars??

  4. #4
    old fart Frans C's Avatar
    Join Date
    Oct 1999
    Location
    the Netherlands
    Posts
    2,926
    Well, actually &HHE isn't hex code.
    &H means a hexadecimal number will follow. Hexadecimal numbers go from 0 to F. H isn't hex, so HE isn't also.

  5. #5

    Thread Starter
    Member
    Join Date
    Aug 2000
    Posts
    57

    That's what I thought

    This encryption class is really irritating.
    In theory it should be *cake* to use but I keep getting
    0 byte files.
    I even had it working earlier, I just re-wired the app the wrong way. I was trying to fix it by integrating the hex conversion of the key , which is what a sample frm tried to do but wouldn't compile.
    I have sum tweaking to do..
    Thanx

  6. #6
    So Unbanned DiGiTaIErRoR's Avatar
    Join Date
    Apr 1999
    Location
    /dev/null
    Posts
    4,111

    Re: Just CLng it!

    Originally posted by Yonatan
    Use CLng!
    Code:
    lblHex.Caption = CLng("&H12AB") ' Convert hexadecimal "12AB" to an integer
    Simple as that!
    Val("&H12AB")

    Would work the same as CLng.

    Oh yes, if you're converting characters to Hex I'd reccomend doing:

    String2Hex = "Vb-World!"
    for x = 1 to len(String2Hex)
    NewHexStr = NewHexStr & format(hex$(asc(mid$(String2Hex,x,1))),"##00")
    'format is to maintain 2 character hex REQUIRED for chr$(0-9)
    next

    and to bring it back:

    Hex2String = "56622D576F726C6421"
    for x = 1 to len(Hex2String) step 2
    NewStr = NewStr & chr$(val("&H" & mid$(Hex2String,x,2)))
    next x

  7. #7

    Thread Starter
    Member
    Join Date
    Aug 2000
    Posts
    57

    Unhappy I gave up on converting the Key

    unfortunately, I can't figure out how much crack the guy was smoking who did the sample form to show me how to use his vbClass
    turns out - you need to compile the class into a dll, and then it will do long number addition without screwing it up.. i wasn't doing that.. also, he was trying to stuff
    &h with two letters from your key
    so if your key was zzzzzzzzzzzzzzzz (16 chars)
    the 'hex' code would be &hzz
    which doesn't work
    so... Clng probably wasn't converting the hex to integer for me for either of those reasons, I'm not sure wether or not I am going to try to emulate what he was doing to the key before setting it as a property
    I think he was just basically trying to make the key more complex, but if you mess with the key like that to encrypt it you have to be able to un-mess with it to decrypt and I have way too much stuff to do to try to throw in some extra security on what is already a pretty random 16 byte key and a strong 128 bit encryption.
    Phwew

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