Decimal to Hexadecimal

Reply

Join Date: Mar 2007
Posts: 1,521
Reputation: Lardmeister is an unknown quantity at this point 
Solved Threads: 22
Lardmeister's Avatar
Lardmeister Lardmeister is offline Offline
Posting Virtuoso

Decimal to Hexadecimal

 
0
  #1
Mar 26th, 2007
When I run:
  1. dec = 255
  2. print hex(dec)
I get 0xff, but I like to get just 'ff'
Reply With Quote Quick reply to this message  
Join Date: Sep 2005
Posts: 133
Reputation: mawe is an unknown quantity at this point 
Solved Threads: 58
mawe mawe is offline Offline
Junior Poster

Re: Decimal to Hexadecimal

 
0
  #2
Mar 26th, 2007
This should do what you want:
  1. print "%x" % 255
Reply With Quote Quick reply to this message  
Join Date: Apr 2006
Posts: 148
Reputation: ghostdog74 is on a distinguished road 
Solved Threads: 40
ghostdog74 ghostdog74 is offline Offline
Junior Poster

Re: Decimal to Hexadecimal

 
0
  #3
Mar 26th, 2007
Originally Posted by Lardmeister View Post
When I run:
  1. dec = 255
  2. print hex(dec)
I get 0xff, but I like to get just 'ff'
'0x' always appears in front, so if you want to use hex() and get rid of 0x, use hex(255)[2:]
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC