On 04/29/2013 10:28 AM, sparkle Plenty wrote:
Hi, I need some hints on where to start solving this problem. I have to interpret a one-byte floating point number as a range between 0 and 240. This is for a gui that controls an amplifier. I am getting a value such as 0.8367 from a fader control, and my Python is interpreting it as either a 0 or 1. I need to define this number to Python as an integer value between 0 and 240. I know that in hex I have the potential for numbers from 0 to 255 within my one byte of available space, and the value will be sent from gui to amp and back as a packed one-byte number. I have looked at the math module and so far, I am still stuck.
Are you serious? There are so many ambiguities and contradictions in your paragraph that each reply so far is entirely different.
Do you have one device that you're sending to and receiving from? Is that device called both an amp and a fader? Is it designed already, and does it already have an interface that talks to your machine? Do specs exist for that interface? If so, be more specific.
At the other end, you have a GUI that's displaying something, and interacting somehow with a user. Perhaps that's not written yet, but do you have plans for it? Are you going to mimic the fader on the amp with a slider on the GUI? Or what?
One byte floating point? Nonsense. While it can be defined (see eryksun's response, which tracks the IEEE standard quite well), it wouldn't store enough precision to be used for anything but a toy.
Shall we continue making up possibilities, or is there a spec you can tell us about? Do you get a one-byte unsigned int value from the device, and some library you implied ("Python is interpreting it as...") is converting it to a float? Is that float value meaningful, or are you trying to fix its misinterpretation?
When you mention logarithms, are you vaguely implying that you are converting from DB scale (to be used in the GUI) to a linear scale (to send as one byte value)? That would be a lousy spec (see second paragraph above).
Draw a better picture, and you'll get more meaningful responses. -- DaveA _______________________________________________ Tutor maillist - [email protected] To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
