dcsimg
Results 1 to 8 of 8

Thread: Adding hexadecimal

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2011
    Posts
    5

    Adding hexadecimal

    Hello.
    I am new at forum. I am trying to write a program which will adding to hexadecimal numbers. I have a word EN and i will find CRC code of it as 93. E is 45 and N is 4E. And then i would like to finf 93 for CRC code of EN. I wrote a program which finds 45 and 4E but i cant add them.

  2. #2
    Frenzied Member
    Join Date
    Jun 2006
    Posts
    1,098

    Re: Adding hexadecimal

    Hexadecimal numbers are strings. You don't want to do any mathematical operation with strings. Instead, add the values you used to get the hexadecimal numbers. The sum is decimal 147, which is hexadecimal 93.

  3. #3

    Thread Starter
    New Member
    Join Date
    Oct 2011
    Posts
    5

    Re: Adding hexadecimal

    Ok. But how i can do this? For example i have a word MOVE 1. When I write this into text box as a MOVE 1 i want to find hexadecimal 88 into an other textbox.

  4. #4

    Thread Starter
    New Member
    Join Date
    Oct 2011
    Posts
    5

    Re: Adding hexadecimal

    I wrote a program to do this but now i have an other problem. When addition of numbers reach 256, program isnt working and giving error.

    Private Sub Command8_Click()
    Data = Text4.Text
    Counter = 1
    Sonuc = 0
    KarakterSayisi = Len(Data)
    Do While Counter < KarakterSayisi + 1
    Karakter = Mid(Data, Counter, 1)
    Donusturucu = Asc(Karakter)
    a = Donusturucu
    b = Sonuc
    c = a + b
    Sonuc = Donusturucu + Sonuc
    Counter = Counter + 1
    Loop
    Sonuc = Hex(c)
    Text5.Text = Sonuc
    End Sub

  5. #5
    Fanatic Member
    Join Date
    Mar 2009
    Posts
    804

    Re: Adding hexadecimal

    Still not clear what you're trying to do.
    Add 2 numbers & show hex result:
    Dim Hx As String
    Hx = Hex$(Num1 + Num2)
    The reverse:
    Dim Total As Long
    Total = Val("&H" & Hx)

  6. #6
    Frenzied Member
    Join Date
    Jan 2010
    Location
    Connecticut
    Posts
    1,687

    Re: Adding hexadecimal

    Quote Originally Posted by Korhan793 View Post
    When addition of numbers reach 256, program isnt working and giving error.
    When you get en error and want help with it you need to tell us what the error is and what line it is happening at.
    VB6 Library

    If I helped you then please help me and rate my post!
    If you solved your problem, then please mark the post resolved

  7. #7
    Frenzied Member
    Join Date
    Jun 2006
    Posts
    1,098

    Re: Adding hexadecimal

    First off, you should use Option Explicit and declare all of your variables.
    What is Option Explicit, and why should I use it?

    Command8, Text4 and Text5 are meaningless names.
    Use the Properties Window (F4) to change the names to something more meaningful.
    Code:
    Private Sub Command8_Click()
      Dim strData As String
      Dim lngCounter As Long
      Dim lngCharCode As Long
      Dim lngSum As Long
    
      strData = Text4.Text
      ' For each character in the string...
      For lngCounter = 1 To Len(strData)
        ' Get the character code
        lngCharCode = Asc(Mid$(strData, lngCounter, 1))
        ' Add this to the sum. The "And &HFF&" keeps the sum under 256
        lngSum = (lngSum + lngCharCode) And &HFF&
      Next lngCounter
      Text5.Text = Hex(lngSum)
    End Sub
    Instead of using the bitwise And operation, you could subtract 256 from the sum whenever it is greater than 255.

  8. #8

    Thread Starter
    New Member
    Join Date
    Oct 2011
    Posts
    5

    Re: Adding hexadecimal

    I solved my problem thanks a lot.

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width