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 14 12477
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?
First of all, you *do* realize that your "8.8 notation"
as specified is not a onetoone function, right? For
example, if 0x0104 is equal to 1.4, then so is 0x008C.
But here you go, as requested...
/* the original number */
unsigned int eight_eight = 0x0104;
/* extract the fields */
unsigned int int_part = eight_eight >> 8;
unsigned int frac_part = eight_eight & 0xFF;
/* put it back together rightways */
double result = int_part + frac_part/100.0;
(Or in a function:)
double from_88(unsigne d int val)
{
/* no errorchecking on range of 'val' */
return (val>>8) + (val & 0xFF)/100.;
}
unsigned int to_88(double val)
{
/* no errorchecking on range of 'val' */
unsigned int ival = (unsigned int) val;
unsigned int fval = (unsigned int) (100*(valival) + 0.5);
return (ival << 8) + fval;
}
HTH,
Arthur
On Wed, 1 Oct 2003, Arthur J. O'Dwyer wrote: 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
First of all, you *do* realize that your "8.8 notation" as specified is not a onetoone function, right? For example, if 0x0104 is equal to 1.4, then so is 0x008C.
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 floatingpoint value 1.4! If 0x0104 is 1.4, then
what's 1.04? And what does 0x0140 represent in your
notation?
If you really didn't make a typo there, this could be
a *really* interesting format...
My solution assumes you meant 0x140 <==> 1.4, BTW.
Arthur
"John T." <jo**@dat.com > 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?
Yes: by hand. C has no function for this, since fixedpoint types are
not part of C. However, it wouldn't be hard to write one yourself.
Hints: %, /, 0x100 and/or 0xFF, (float), +.
Richard
On Wed, 1 Oct 2003 08:03:12 +0200
"John T." <jo**@dat.com > 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?
So what is your question about C? All I see is a question about
algorithms which belongs else where, such as comp.programmin g possibly.
However, to get you started...
First check your specification. I would expect 0x0104 to be 1.015625
(this is the type of fixed point notation I've always found).
If I am right you just have to do floating point division by 256. If you
are write you have to do some masking to seperate the two octets, scale
them then add them together.
Post here when you have attempted to write the C code and hit problems.

Mark Gordon
Paid to be a Geek & a Senior Software Developer
Although my email address says spamtrap, it is real and I read it.
"John T." <jo**@dat.com > writes: 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?
Not without a better specification of your notation.
I'd normally expect a 16bit fixedpoint notation to have the
highorder 8 bits represent the integer part and the loworder 8 bits
represent the fractional part, with 0x0001 representing 1.0/256.0,
0x00FF representing 255.0/256.0, etc. In that case, you'd simply
multiply by 256.0.
Or you could have the loworder 8 bits represent a multiple of 0.01
(decimal) rather than of 1.0/256.0; in that case, you'd have to
extract the highorder and loworder parts and do a little arithmetic.
In such a notation, though, 0x0104 would be 1.04, not 1.4; was that
just a typo? Such a notation is a bit inefficient, since you're using
8 bits to represent any of 100 values rather than 256 values. If
that's what you're dealing with, though, it's merely odd, not wrong.
Keep in mind that some fractional values, such as 0.1, cannot be
represented exactly in binary floatingpoint. Note also that your
format has no way of representing negative numbers.

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"
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?
Divide the unsigned short value by 256.0
If you don't like the resulting decimal fraction,
then explain it better.
0xff11 is 255.066406
0x104 is 1.015625
0x2356 is 35.335938
0xffff is 255.996094

pete
Keith Thompson wrote: Or you could have the loworder 8 bits represent a multiple of 0.01 (decimal) rather than of 1.0/256.0; in that case, you'd have to extract the highorder and loworder parts and do a little arithmetic. In such a notation, though, 0x0104 would be 1.04, not 1.4; was that just a typo? Such a notation is a bit inefficient, since you're using 8 bits to represent any of 100 values rather than 256 values. If that's what you're dealing with, though, it's merely odd, not wrong.
Keep in mind that some fractional values, such as 0.1, cannot be represented exactly in binary floatingpoint. Note also that your format has no way of representing negative numbers.
In the latter case (the innefficient approach) the "unused" bit can be used
to denote the sign. Just to make things even weirder :)
0x0140 = 1.40
0x01C0 = 1.40
But given the amount of contraints he as already put on his range, I think
the fact that it will be able to hold a sign is apparently out of the
question. :)

Martijn http://www.sereneconcepts.nl
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 floatingpoint 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.

Christopher BensonManica  Jumonji giri, for honour.
ataru(at)cybers pace.org 
Christopher BensonManica <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 floatingpoint 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.
This would make 0x0101 and 0x010A the same thing, yesno? And there
would be no way to represent 1.01, yesno?
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.

/ 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! /
"All that flower power is no match for my glower power!"
 Montgomery Burns 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...

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...
 
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...

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 "richlytyped" .NET
framework. But, after almost *two years* of "giving it a chance," I still
insist...

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...

by: bearophileHUGS 
last post by:
>From this interesting blog entry by Lawrence Oluyede:
http://www.oluyede.org/blog/2006/07/05/europythonday2/
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()...

by: marktang 
last post by:
ONU (Optical Network Unit) is one of the key components for providing highspeed 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...

by: Oralloy 
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bitfields 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. ...
 
by: tracyyun 
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, ZWave, WiFi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...

by: agi2029 
last post by:
Let's talk about the concept of autonomous AI software engineers and nocode agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...

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...

by: TSSRALBI 
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LANtoLAN VPNs.
The last exercise I practiced was to create a LANtoLAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in...

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 welldesigned 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...
 