|
-
Oct 15th, 2011, 06:15 PM
#1
Thread Starter
New Member
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.
-
Oct 15th, 2011, 10:44 PM
#2
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.
-
Oct 16th, 2011, 05:09 AM
#3
Thread Starter
New Member
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.
-
Oct 16th, 2011, 06:13 AM
#4
Thread Starter
New Member
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
-
Oct 16th, 2011, 07:22 AM
#5
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)
-
Oct 16th, 2011, 09:22 AM
#6
Re: Adding hexadecimal
 Originally Posted by Korhan793
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
-
Oct 16th, 2011, 09:36 AM
#7
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.
-
Oct 18th, 2011, 12:01 PM
#8
Thread Starter
New Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|