|
The following will work:
float htonf(float value)
{
float result;
char* pSource = reinterpret_cast<char*>(&value);
char* pDest = reinterpret_cast<char*>(&result);
pDest[0] = pSource[3];
pDest[1] = pSource[2];
pDest[2] = pSource[1];
pDest[3] = pSource[0];
return result;
}
Warning: once a value has been converted to network order do not try to use it on the host, since it is almost certainly an invalid IEEE 754 format number.
Note that the above function also converts from network to host format.
Converting doubles is similar:
double htonf(double value)
{
double result;
char* pSource = reinterpret_cast<char*>(&value);
char* pDest = reinterpret_cast<char*>(&result);
pDest[0] = pSource[7];
pDest[1] = pSource[6];
pDest[2] = pSource[5];
pDest[3] = pSource[4];
pDest[4] = pSource[3];
pDest[5] = pSource[2];
pDest[6] = pSource[1];
pDest[7] = pSource[0];
return result;
}
Graham
Librarians rule, Ook!
|
|
|
|
|
Graham, will this code work between platforms with different memory layouts, since you:
1/ always change the float regardless of the endianess of the source platform (it assumes running on little-Endian)?
2/ is the float memory layout guaranteed to look like this on other platforms (Intel, ARM, PowerPC, etc)?
Cheers, M
|
|
|
|
|
1. You are correct that this always changes the float. The original version is suitable for use on Intel platforms. A portable version is as follows:
bool IsBigEndian()
{
int i = 1;
char* p = reinterpret_cast<char*>(&i);
return *p == 0;
}
float htonf(float value)
{
if(IsBigEndian())
return value;
float result;
char* pSource = reinterpret_cast<char*>(&value);
char* pDest = reinterpret_cast<char*>(&result);
pDest[0] = pSource[3];
pDest[1] = pSource[2];
pDest[2] = pSource[1];
pDest[3] = pSource[0];
return result;
}
2. The assumption here is that float is a single precision IEEE 754 binary floating point and double is a double precision IEEE 754 binary floating point. Whereas early in my career there were a number of different types of floating point support, IEEE 754 is now ubiquitous. So Intel/AMD, Sparc, PowerPC all support IEEE 754. I'm not familiar with the ARM platform, but it looks like this also support IEEE 754
Graham
Librarians rule, Ook!
|
|
|
|
|
Graham Shanks wrote: The assumption here is that float is a single precision IEEE 754 binary floating point and double is a double precision IEEE 754 binary floating point
Ok thanks! I didn't know the binary representation is the same (apart from the memory layout) and directly suitable as interchange format.
|
|
|
|
|
Graham,
Thanks very much!!
Regards,
Vishal Soni
|
|
|
|
|
In my application i need to print info 0f 150 employees on a printer.if i tried to print all employees info at a time ,EndPage() returning negitive value otherwise it is printing normally.(no file is currepted)please provide some information on this......
kir_MFC
|
|
|
|
|
help us to understand you and we will be able to help you better. In other words... a bit more info would be nice.
For instance:
Which language/version of VS are you using?, What have you tried (relevant code of your print function would not be bad)?...
EDIT: On the other hand... have you looked here[^] ?
I found another article[^], it is a bit old, but it has a lot of info that may be helpful for you.
Regards.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
Rating helpfull answers is nice, but saying thanks can be even nicer.
modified on Friday, January 8, 2010 11:09 AM
|
|
|
|
|
Have you called GetLastError() when EndPage() returns a negative value? The code returned by GetLastError() will probably give you a clue as to what is going on.
You may be right
I may be crazy
-- Billy Joel --
Within you lies the power for good - Use it!
|
|
|
|
|
Hi,
My CListCtrl has 2 columns of data, but I don't want to show the column headers, just the data.
Is this possible?
TIA
Tony
|
|
|
|
|
If it is not conditionally visible, you can set a empty string for that column, though simple but fits your requirement.
HTH
|
|
|
|
|
Problem solved,
I should play about with the Dialog Editor more and see the option to show header control..........
Tony
|
|
|
|
|
Can you share the information?
|
|
|
|
|
Sure,
In the VS Resource Editor, one of the properties of the CListCtrl that you can set is "No Column Header".
I set this TRUE and my column header disappeared, as required.
HTH
Tony
|
|
|
|
|
I may be wrong, but there is probably an API call to do this as well. You likely need to use GetWindowLong() to obtain the style settings, then remove the bit that sets "No Column Header" and findally call SetWindowLong() with the new style settings.
Chris Meech
I am Canadian. [heard in a local bar]
In theory there is no difference between theory and practice. In practice there is. [Yogi Berra]
|
|
|
|
|
Hi,
Im using MDI applcation.
In that I want to Hide the mainframe,but i want to display all child windows.
How can i do tht?
When i coded SW_HIDE for mainframe in InitInstance().I cannot get the childwindow.
Is anyother way possible to show child window without Mainframe?
Anu
|
|
|
|
|
You're attempting to use the framework in a way for which it wasn't intended. While you may in the end get the results you're looking for, in all likelihood you won't; you will probably keep running into issues where the framework is doing something that's incompatible with your scheme. The reason is simple - like I said, you're trying to use the framework in a way for which it wasn't intended.
Typically, when you run into a situation like this, your code will get uglier and uglier as you try to force the framework to your purpose. The ugly code is trying to tell you something - you need to rethink your approach to the problem. Why on earth do you want child windows all over the place but no mainframe? (Don't answer - I'm really not interested in debating the wisdom of your scheme.)
The bottom line is this. If you're going to use MFC, you're going to be a lot better off if you go with the flow and stop trying to force the framework to do something it wasn't designed for. You would be better off finding a framework that supports the architecture you're trying to implement.
[edit]
Grammar fixes.
[/edit]
L u n a t i c F r i n g e
modified on Friday, January 8, 2010 10:42 AM
|
|
|
|
|
In VC2010, there's a c++ app wizard that lets you create multiple top level windows - maybe that's what you want?
Iain.
ps, In VC6, I know of no whay to do what you're asking, especially if you want to show and then hide the CMainFrame.
I have now moved to Sweden for love (awwww).
|
|
|
|
|
Hi I just came across a function like
void (int a, int b,...)
{
//code
}
I assumed it as variable argument..But am I correct? If yes, how does it work exactly?...
-----------------------------
I am a beginner
|
|
|
|
|
What about documentation [^], [^]?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
hrishiS wrote: I assumed it as variable argument.
Your assumption is correct; see here[^] for documentation on how to implement this feature.
|
|
|
|
|
Hi to All,
I want to create a sine-wave like the one in (Windows Task Manager->performance Bar)..which should be moving depending upon some input.....
Please give me some hints
-----------------------------
I am a beginner
|
|
|
|
|
Could you be a bit more explicit ? What do you mean exactly by creating a sine wave ?
Do you want to display some signal on the screen ? Are you looking for a kind of chart control ? If yes, take a look at my sig.
|
|
|
|
|
Thanks for the reply
I know my questions is not specific.
I am just doing this to just to learn.I am a VC++ learner. when i was looking at the windows task manager performance tab, it strike my head to create something like that, ...since then i am breaking my head....I guess you can assume just drawing a signal....
-----------------------------
I am a beginner
|
|
|
|
|
If you want to learn how to do something like that, the easiest way is to look at the code of another example[^]
|
|
|
|
|
thanks
I will go through that and if u dont mind, i will get back to you for further doubts..
-----------------------------
I am a beginner
|
|
|
|