You Are Here:

Community: Developer Discussion Boards

#1 Old Signed float to Hex conversion - 2009-03-08, 15:47

Join Date: Oct 2008
Posts: 1
davi.graner
Offline
Registered User
Hi,
Im implementing a communication protocol in pys60 and i need to convert from signed float (-122.7886577) to hex and from hex to signed float.
How can i convert preserving the signal and the precision?
At this time i can only make the conversion between int and hex.

Tks for help.

Marcos Davi Reis
Reply With Quote

#2 Old Re: Signed float to Hex conversion - 2009-03-09, 01:45

Join Date: Nov 2007
Posts: 319
Location: Sertaozinho/Brazil
Send a message via MSN to marcelobarrosalmeida Send a message via Skype™ to marcelobarrosalmeida
marcelobarrosalmeida's Avatar
marcelobarrosalmeida
Offline
Forum Nokia Champion
hi Marcos, fine ?

when I write network programs I like to use struct module.
With it you have the necessary control like byte order, padding, and so on.
Using struct.pack to format an output buffer is simple. Just check this link:

http://docs.python.org/library/struct.html

Code:
import struct
data = struct.pack("f",-123.456)
struct.unpack is used to do the reverse operation (from bytes to python)

Marcelo Barros


Marcelo Barros
Nokia E71, N800, N95 and XM 5800
http://www.croozeus.com
http://wordmobi.wordpress.com
http://jedizone.wordpress.com
Reply With Quote
Reply « Previous Thread | Next Thread »
Display Modes
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules

You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump
Similar Threads
Thread Thread Starter Forum Replies Last Post
Conversion Hex to Decimal heidis General Symbian C++ 9 2008-10-18 12:55
Conversion from signed 2 unsigned Shaddy_ General Symbian C++ 1 2007-03-12 11:55
conversion of float to text shafali gupta Symbian User Interface 1 2005-01-25 20:17
Float using henson float Pandaemonium Mobile Java General 2 2004-03-24 11:40
UDH Hex conversion yewseong Smart Messaging 1 2003-08-28 19:04

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia