Conversion to Hex or other bases 
Author Message
 Conversion to Hex or other bases

How can I convert a decimal to another base? i.e. Hex or binary?

--
Bye,
   Gerhard
If you are programming dynamic HTML in python you might find 'template.py'
usefull. Look at my homepage: http://www.*-*-*.com/



Thu, 05 Sep 2002 03:00:00 GMT  
 Conversion to Hex or other bases
Gerhard Gruber wrote in comp.lang.python:

Quote:
> How can I convert a decimal to another base? i.e. Hex or binary?

This question has been asked several times in the last few days.
I'll just give a quick answer:

"%o" % 31
Gives '37', 31 in octal.

"%x" % 31
Gives '1f', 31 in hexadecimal.

There isn't any other way for other bases that I can think of (well, apart
from str(x) to get the decimal :-)). You need to roll your own or look at
the recent posts on this subject for a function that handles any base
up to 36 (10 digits + 26 characters).

--

   This is no way to be
     Man ought to be free      -- Ted Bundy
       That man should be me



Thu, 05 Sep 2002 03:00:00 GMT  
 Conversion to Hex or other bases
You can get hex or octal string from a decimal number using

1. hex() function :   hex(23)
2. 'formatted string' : hex = "%x" % 23

both gives you '0x17'

Gang


Quote:
> How can I convert a decimal to another base? i.e. Hex or binary?

> --
> Bye,
>    Gerhard
> If you are programming dynamic HTML in python you might find 'template.py'
> usefull. Look at my homepage: http://members.aon.at/sparhawk



Fri, 06 Sep 2002 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. number base conversion? (ASCII to Hex)

2. Hex to Bin, Bin to Hex, Hex to Dec, Dec to Hex

3. Base 10 to base 2 conversion in assembly

4. Base 10 to base 2 conversion in assembly

5. Delphi conversion and DLL from others

6. [Fwd: Re: Hex to decimal conversion = ?]

7. Hex to decimal conversion = ?

8. Hex to Decimal Conversion

9. hex conversions

10. hex value to integer conversion

11. VB hex constant conversion

12. Hex ColorDialog Conversion

 

 
Powered by phpBB® Forum Software