Question for hexadecimal masters only!

  • Thread starter Thread starter MatuX
  • Start date Start date
M

MatuX

Guest
Anyone knows how is the equation to convert decimals to hexadecimals?

For example:

41500 -> A21C

I had it written somewhere, but I lost it long time before, if anyone can help me I would be veeeeeeeeeeeeeery grateful!!

Thanks
 
>Anyone knows how is the equation
>to convert decimals to hexadecimals?
>
>
>For example:
>
>41500 -> A21C
>
>I had it written somewhere, but
>I lost it long time
>before, if anyone can help
>me I would be veeeeeeeeeeeeeery
>grateful!!
>
>Thanks

Well, aside from plain conversion like in a calculator, is this for a program? And if so, what language?
 
Come on, guys... My question was clear.

What is the *equation* used for decimal to hexa conversion. Anyone knows it?

It is for a VB program, why?
 
>Come on, guys... My question was
>clear.
>
>What is the *equation* used for
>decimal to hexa conversion. Anyone
>knows it?

I've got a working program in C/C++.

Basically you divide the number by a power of 16, one that divides into the number less than 16 times (or you must choose a higher power), then take that number and convert it to hex (0123456789ABCDEF). Then subtract that value * 16^power, and repeat with a lower-order power.

Ex:
[pre]

for i = 10 to 1, step -1
{
Temp = Number / (16^i)

if Temp = 0, HexNumber:Character(i) = '0'
if Temp = 1, HexNumber:Character(i) = '1'
...
if Temp = 15, HexNumber:Character(i) = 'F'

Number = Number - (Temp * (16^i))
}

[/pre]

I had to make it (i-1) in my equations (but not the for loop) for it to work properly.

>It is for a VB program,
>why?

Because some of us have source code for certain languages like C/C++.

You may consider using a function like HEX() in VB if there is one. No use reprogramming the wheel.

-Xotor-

[div align=center]

http://www.poseidonet.f2s.com/files/nostupid.gif
[/div]
 
Or, you could just use a calculator which converts from hexadecimal-decimal and back (you make less mistakes and don't have to memorize long equations).

I can email you the one I use.


[TABLE border=5' cellspacing='0' cellpadding='15' bgcolor='#000000' bordercolor='#808080' bordercolorlight='#C0C0C0' bordercolordark='#000000][TR][TD]

[/center]
[TABLE border=0' cellspacing='0' cellpadding='0' bgcolor='#000000][TR][TD]
[TD][center][font face=arial, helvetica, ms sans serif" color="red][a href=mailto: [email]sea_man_stains__@hotmail.com[/email]]Smackrazor[/a][/center]
[font face=arial, helvetica, ms sans serif" color="silver]Webmaster: [a href=//www.pipboy2000le.f2s.com]PIPBoy 2000 LE[/a]
Co-webmaster: [a href=//www.diepokemon.f2s.com]NPA[/A][/TD][/TR]
[/TABLE][/TD][/TR][/TABLE]​
 
>Or, you could just use a
>calculator which converts from hexadecimal-decimal
>and back (you make less
>mistakes and don't have to
>memorize long equations).
>
>I can email you the one
>I use.

I think he wants it so he can program it into his program to give values or actually compute the values to print out to the files themselves.

Windows Calculator works pretty good for me actually.

[div align=center]

http://www.poseidonet.f2s.com/files/nostupid.gif
[/div]
 
Thanks

Thanks, Xotor, it's going to be very useful :-)

>Because some of us have source code for certain
>languages like C/C++

I can translate arithmetic algorithms from C to VB (it's not very hard, thought), so, if you have any interesting hex code you can show me it (I'm learning C and C++, too)

>You may consider using a function like HEX() in
>VB if there is one. No use reprogramming the
>wheel

Yes, but my problem is that I need to save the values to a file in an endian fashion [H] [L], and the Hex() function gives me the full value (eg: FF1CE2) and I don't find another way than reversing the value to save it correctly.
I want to be practical, so if I have to place a byte for every..... no wait......

I have another idea! Thanks!!!!! ;)))))))
 
>>Or, you could just use a
>>calculator which converts from hexadecimal-decimal
>>and back (you make less
>>mistakes and don't have to
>>memorize long equations).
>>
>>I can email you the one
>>I use.
>
>I think he wants it so
>he can program it into
>his program to give values
>or actually compute the values
>to print out to the
>files themselves.

Oh, right.

>Windows Calculator works pretty good for
>me actually.


It takes up too much of my screen so I don't use it.


>[div align=center]

>http://www.poseidonet.f2s.com/files/nostupid.gif
>[/div]


[TABLE border=5' cellspacing='0' cellpadding='15' bgcolor='#000000' bordercolor='#808080' bordercolorlight='#C0C0C0' bordercolordark='#000000][TR][TD]

[/center]
[TABLE border=0' cellspacing='0' cellpadding='0' bgcolor='#000000][TR][TD]
[TD][center][font face=arial, helvetica, ms sans serif" color="red][a href=mailto: [email]sea_man_stains__@hotmail.com[/email]]Smackrazor[/a][/center]
[font face=arial, helvetica, ms sans serif" color="silver]Webmaster: [a href=//www.pipboy2000le.f2s.com]PIPBoy 2000 LE[/a]
Co-webmaster: [a href=//www.diepokemon.f2s.com]NPA[/A][/TD][/TR]
[/TABLE][/TD][/TR][/TABLE]​
 
Back
Top