| View previous topic :: View next topic |
| Author |
Message |
dnsi0 I post too much
Reputation: 0
Joined: 04 Jan 2007 Posts: 2674
|
Posted: Sun Nov 25, 2007 11:15 am Post subject: Question For Hex |
|
|
| How do you convert A Hex number to decimal and dec to hex??? |
|
| Back to top |
|
 |
Blader I post too much
Reputation: 2
Joined: 19 Jan 2007 Posts: 2049
|
|
| Back to top |
|
 |
dnsi0 I post too much
Reputation: 0
Joined: 04 Jan 2007 Posts: 2674
|
Posted: Sun Nov 25, 2007 11:50 am Post subject: |
|
|
| I am trying to make a program... I need the calculation... |
|
| Back to top |
|
 |
Blader I post too much
Reputation: 2
Joined: 19 Jan 2007 Posts: 2049
|
Posted: Sun Nov 25, 2007 11:55 am Post subject: |
|
|
Oh
Divide the decimal by 16 and record the remainder, and do it until the number is 0
Look at the remainders, from last division to first, and that's your hexidecimal
I think, someone told me that one day
Hold on... _________________
|
|
| Back to top |
|
 |
Symbol I'm a spammer
Reputation: 0
Joined: 18 Apr 2007 Posts: 5094 Location: Israel.
|
Posted: Sun Nov 25, 2007 11:56 am Post subject: |
|
|
You want a formula or a function?
Well in delphi its IntToHex.
In C# I think its Convert.ToHex ot something... |
|
| Back to top |
|
 |
dnsi0 I post too much
Reputation: 0
Joined: 04 Jan 2007 Posts: 2674
|
Posted: Sun Nov 25, 2007 12:00 pm Post subject: |
|
|
| My delphi isn't working right now... Can u make a library with IntToHex and HexToInt please? |
|
| Back to top |
|
 |
HolyBlah Master Cheater
Reputation: 2
Joined: 24 Aug 2007 Posts: 446
|
Posted: Sun Nov 25, 2007 2:19 pm Post subject: |
|
|
All numbers are in hex, you just see it in decimal.
But here is 2 functions to convert a decimal number and hexadecimal:
| Code: |
Function HexToDec(NumberAsString:String):String;
begin
Result:=IntToStr(StrToInt('$'+NumberAsString));
End;
Function DecToHex(NumberAsString:String):String;
begin
Result:=Format('%x',[strtoint(NumberAsString)]);
End; |
usage:
| Code: | procedure TForm1.Button1Click(Sender: TObject);
begin
if Button1.Caption='HexToDec' then
begin
Button1.Caption:='DecToHex';
label1.Caption:=HexToDec(label1.Caption);
end
else
begin
Button1.Caption:='HexToDec';
label1.Caption:=DecToHex(label1.Caption);
end
end; |
|
|
| Back to top |
|
 |
dnsi0 I post too much
Reputation: 0
Joined: 04 Jan 2007 Posts: 2674
|
Posted: Mon Nov 26, 2007 5:56 pm Post subject: |
|
|
| Can you make it into visual basic? I wanted to make a program with vb6.0 |
|
| Back to top |
|
 |
Blader I post too much
Reputation: 2
Joined: 19 Jan 2007 Posts: 2049
|
Posted: Mon Nov 26, 2007 6:52 pm Post subject: |
|
|
VB6 actually has hex commands, I just figured it out now XD
Pretty simple, can't believe it's only 1 line of code
So for a converter, you would need a button and 2 text boxes
So text1 = the decemal, and text2 = the converted hex
| Code: | Private Sub Command1_Click
text2.text = Hex(text1.Text)
End Sub |
_________________
|
|
| Back to top |
|
 |
dnsi0 I post too much
Reputation: 0
Joined: 04 Jan 2007 Posts: 2674
|
Posted: Mon Nov 26, 2007 7:54 pm Post subject: |
|
|
| How to UNhex??? |
|
| Back to top |
|
 |
Blader I post too much
Reputation: 2
Joined: 19 Jan 2007 Posts: 2049
|
Posted: Mon Nov 26, 2007 7:56 pm Post subject: |
|
|
Umm, you could try saving the number before, or, try this
Dec(whatever here)
Not sure if it could work though
Nvm it doesn't
Try this for saving
Goes under button click
| Code: | Dim decimal as String
decimal = text1.text
text2.text = Hex(decimal) |
As for converting back, on another button
| Code: | | text1.text = decimal |
_________________
|
|
| Back to top |
|
 |
dnsi0 I post too much
Reputation: 0
Joined: 04 Jan 2007 Posts: 2674
|
Posted: Mon Nov 26, 2007 7:59 pm Post subject: |
|
|
Dec() is not a function.
But I did find Oct() but its not for converting hex -> dec... |
|
| Back to top |
|
 |
Blader I post too much
Reputation: 2
Joined: 19 Jan 2007 Posts: 2049
|
Posted: Mon Nov 26, 2007 7:59 pm Post subject: |
|
|
I edited my post, try it _________________
|
|
| Back to top |
|
 |
dnsi0 I post too much
Reputation: 0
Joined: 04 Jan 2007 Posts: 2674
|
Posted: Mon Nov 26, 2007 8:03 pm Post subject: |
|
|
Blader I found it on google lol.
| Code: | For y = 1 To Len(Text1.Text)
num = Mid(Text1.Text, y, 2)
Value = Value & Val("&h" & num)
y = y + 1
Next y
Text2.Text = Value |
It works lol. |
|
| Back to top |
|
 |
sphere90 Grandmaster Cheater
Reputation: 0
Joined: 24 Jun 2006 Posts: 912
|
Posted: Mon Nov 26, 2007 8:05 pm Post subject: |
|
|
| Use the Calculator provided by Windows. |
|
| Back to top |
|
 |
|