Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

how to convert double between host and network byte order?

Status
Not open for further replies.

mashhur

Member level 5
Member level 5
Joined
Jan 21, 2009
Messages
91
Helped
6
Reputation
12
Reaction score
4
Trophy points
1,288
Activity points
1,863
could somebody pls tell me how to convert double precision into network byte ordering. i tried

uint32_t htonl(uint32_t hostlong);
uint16_t htons(uint16_t hostshort);
uint32_t ntohl(uint32_t netlong);
uint16_t ntohs(uint16_t netshort);
functions and they worked well but no of them does double (float) conversion cuz these types are apart different on every architecture. And through the XDR i found double-float precision format representations(https://en.wikipedia.org/wiki/Double_precision) but no byte ordering there.

So, i would much appreciate if somebody helps me out on this (C code would be great!). NOTE: OS is Linux kernel (2.6.29), ARMv7 CPU architecture.

thanks!
 

A bytewise permutation from source to target data would be the most simple way.
Code:
for (i=0;i<8;i++)
  *((char *)&target+i) = *((char *)&source+7-i);
To take advantage from a possibly more effective implementation of htonl() you can apply it crosswise between upper and lower long part of source and target.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top