I have a number in 8.8 notation that I wish to convert to a float.......
8.8 notation is a 16 bit fixed notation, so:
0xFF11 is the number 255.17
0x0104 is the number 1.4
0x2356 is the number 35.86
and so on....
Any ideas on how to convert this into a float?
John
Nov 13 '05
14 12570
On Wed, 1 Oct 2003, John T. wrote: I have a number in 8.8 notation that I wish to convert to a float....... 8.8 notation is a 16 bit fixed notation, so: 0xFF11 is the number 255.17 0x0104 is the number 1.4 0x2356 is the number 35.86 and so on.... Any ideas on how to convert this into a float?
Your examples don't tell me how I deal with numbers like:
0x0064
Is this 0.100 or is this 1.00?
Obviously, the first step is seperating the number into the whole number
and the fraction:
/* let n be the number we are dealing with */
float result;
int whole = (n >> 8) & 0xff;
int fraction = n & 0xff;
If the first method is the desired result you would need:
if(fraction > 99)
result = whole + fraction/100.0;
else
result = whole + fraction/10.0;
If the second method is the desired result you would need:
result = whole + fraction/10.0;
--
Send e-mail to: darrell at cs dot toronto dot edu
Don't send e-mail to vi************@ whitehouse.gov
Joona I Palaste <pa*****@cc.hel sinki.fi> spoke thus: This would make 0x0101 and 0x010A the same thing, yesno?
Hm, yes, if he's trying to convert these to floats.
And there would be no way to represent 1.01, yesno?
Again, yes, although I'm not sure he wants to. The format itself makes sense
(although I don't know what one would use it for).
Either his "." means a different thing than the fraction separator in decimal, he has made a few typos, or he doesn't understand his own function.
I'm betting on the first one, but I'm not sure...
--
Christopher Benson-Manica | Jumonji giri, for honour.
ataru(at)cybers pace.org |
Christopher Benson-Manica wrote: Joona I Palaste <pa*****@cc.hel sinki.fi> spoke thus:
This would make 0x0101 and 0x010A the same thing, yesno?
Hm, yes, if he's trying to convert these to floats.
And there would be no way to represent 1.01, yesno?
Again, yes, although I'm not sure he wants to. The format itself makes sense (although I don't know what one would use it for).
The format is kind of lame IMO. Why not use 0x[0-9A-Z]{2}[0-9]{2} to
represent 000.00 to 255.99? This is only slightly less efficient, but
much more straightforward .
/david
--
Andre, a simple peasant, had only one thing on his mind as he crept
along the East wall: 'Andre, creep... Andre, creep... Andre, creep.'
-- unknown
David Rubin <bo***********@ nomail.com> scribbled the following: Christopher Benson-Manica wrote: Joona I Palaste <pa*****@cc.hel sinki.fi> spoke thus: > This would make 0x0101 and 0x010A the same thing, yesno? Hm, yes, if he's trying to convert these to floats.
> And there > would be no way to represent 1.01, yesno?
Again, yes, although I'm not sure he wants to. The format itself makes sense (although I don't know what one would use it for).
The format is kind of lame IMO. Why not use 0x[0-9A-Z]{2}[0-9]{2} to represent 000.00 to 255.99? This is only slightly less efficient, but much more straightforward .
Because (10+26) squared is 1296, not 256?
--
/-- Joona Palaste (pa*****@cc.hel sinki.fi) ---------------------------\
| Kingpriest of "The Flying Lemon Tree" G++ FR FW+ M- #108 D+ ADA N+++|
| http://www.helsinki.fi/~palaste W++ B OP+ |
\----------------------------------------- Finland rules! ------------/
"A computer program does what you tell it to do, not what you want it to do."
- Anon
Joona I Palaste <pa*****@cc.hel sinki.fi> writes: Christopher Benson-Manica <at***@nospam.c yberspace.org> scribbled the following: Arthur J. O'Dwyer <aj*@nospam.and rew.cmu.edu> spoke thus: Wait a minute... I realized as soon as I sent that message that I can't think of *any* reasonable way to get 0x0104 from the floating-point value 1.4! If 0x0104 is 1.4, then what's 1.04? And what does 0x0140 represent in your notation? If I'm not mistaken, 0x0140 is 1.64 in his notation.
Either his "." means a different thing than the fraction separator in decimal, he has made a few typos, or he doesn't understand his own function.
The OP wrote: 0xFF11 is the number 255.17 0x0104 is the number 1.4 0x2356 is the number 35.86
Assuming that 1.4 was a typo, and it should be 1.04, the notation
looks odd but consistent. The high-order 8 bits are the integer part;
the low-order 8 bits are the fractional part multiplied by 100.0
decimal. One advantage of such a notation is that it can represent
decimal fractions such as 0.1 or 0.01 exactly; of course, converting
to binary floating-point loses that property.
This would make 0x0101 and 0x010A the same thing, yesno? And there would be no way to represent 1.01, yesno?
Nononono. 0x0101 is 1.01, and 0x010A is 1.10.
It would mean that 0x0164 and 0x0200 would both represent 2.00, but
presumably 0x0164 would be the canonical normalized representation.
I suggest we wait for the OP to come back and tell us what he really
meant.
--
Keith Thompson (The_Other_Keit h) ks*@cts.com <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://www.sdsc.edu/~kst>
Schroedinger does Shakespeare: "To be *and* not to be" This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: jova |
last post by:
Does anyone know of a good site where I can learn of this?
|
by: Robert Mark Bram |
last post by:
Howdy All!
Is there any difference between referencing objects and attributes with dot
notation or bracket notation?
Example,
document.formname.controlname
document
Can I access attributes and objects equally with both?
|
by: S. |
last post by:
if in my website i am using the sgml { notation, is it accurate
to say to my users that the site uses unicode or that it requires
unicode?
is there a mathematical formula to calculate a unicode value given its
utf8 value?
Rgds,
Sam
|
by: Thomas Lorenz |
last post by:
Hello,
I'm a little confused about object initialization. According to Stroustrup
(The C++ Programming Language, Special Edition, Section 10.2.3) constructor
arguments should be supplied in one of the following notations:
MyClass instance1 = MyClass(1, 2, 3);
MyClass instance2(4, 5, 6);
What's curious: the second notation variant is called an "abbreviated form"
|
by: Matthias |
last post by:
I have been told not to use preceding underscores when notating data
members for example. What kind of notation do you use in general? I have
seen Microsoft uses hungarian notation a lot. Is that the most common one?
I also recognized that the more abstract a language becomes, the less
people care about proper notation (i.e. I haven't seen any C# or Java
code using anything even close to hungarian notation).
I have even recognized this...
| |
by: funcSter |
last post by:
I was asked to program using the Dutch Notation with C#.
I am not familiar with the Dutch notation at all. I use the Hungarian.
I asked a programmer friend "What is the Dutch Notation?" He replied,
"Do you mean HUNGARIAN notation?"
So I thought maybe the person who told me to use the Dutch notation
must have been mistaken. Upon doing some research, I realise that the
DUtch notation does exist (hehe pardon my ignorance!), BUT I can't...
|
by: |
last post by:
Just seeking some advice (or solace)...
Am I the only who's having trouble letting go of notation? Having extensive
experience in C++ years ago (both before I jumped into VB3 in college and at
various times during my VB career), I welcomed the "richly-typed" .NET
framework. But, after almost *two years* of "giving it a chance," I still
insist that using notation for the "common" (mostly value-types) types
(string, integer, boolean, etc.)...
|
by: CMM |
last post by:
So after three years of working in .NET and stubbornly holding on to my old
hungarian notation practices--- I resolved to try to rid myself of the
habit. Man, I gotta say that it is liberating!!! I love it.
At first I struggled with how to name controls. I tried to keep some sort of
notation with them... but I threw that away too!!! I now name them as if
they were simply properties of the form (FirstNameLabel, etc.)... which they
ARE!......
|
by: bearophileHUGS |
last post by:
>From this interesting blog entry by Lawrence Oluyede:
http://www.oluyede.org/blog/2006/07/05/europython-day-2/
and the Py3.0 PEPs, I think the people working on Py3.0 are doing a
good job, I am not expert enough (so I don't post this on the Py3.0
mailing list), but I agree with most of the things they are agreeing
to. Few notes:
- input() vanishes and raw_input() becomes sys.stdin.readline(). I
think a child that is learning to program...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |