ntohl


 
Thread Tools Search this Thread
Top Forums Programming ntohl
# 1  
Old 09-07-2008
Power ntohl

my machine is little endian, and binary data that i need to convert is big endian. hence when i try to convert to text, it gives weird values.
does ntohl function in endian.h help??
where can i get endian.h from?

please someone help!!!!
# 2  
Old 09-08-2008
If your binary data is integers ntohl() will help.

WHAT OS? endian.h is not standard for this see:
htons(), htonl(), ntohs(), ntohl()
# 3  
Old 09-08-2008
ntohl

Quote:
Originally Posted by jim mcnamara
If your binary data is integers ntohl() will help.

WHAT OS? endian.h is not standard for this see:
htons(), htonl(), ntohs(), ntohl()

no my binary data is float?? what to use???
# 4  
Old 09-08-2008
ntohl

no my binary data is float!
what to use then if not ntohl???
# 5  
Old 09-08-2008
By float do you mean IEEE-754 (4 bytes)?
# 6  
Old 09-08-2008
try something like this:
Code:
#include <stdlib.h>
#include <netinet/in.h>

float bin2flt(void *src)
{
	typedef union 
                {float flt; long lng; }
             flt_t;
	flt_t val;
	val.lng=ntohl( *(int*)src);
	return val.flt;
}

# 7  
Old 09-09-2008
Quote:
Originally Posted by geet
no my binary data is float?? what to use???
Float's a little more tricky. The binary representation may or may not be recognized by the receiving end, even after changing endianness. Your best bet is to convert to BCD of fixed length, or a string using sprintf and scanf.
Login or Register to Ask a Question

Previous Thread | Next Thread
Login or Register to Ask a Question