Browse DevX
Sign up for e-mail newsletters from DevX

Tip of the Day
Home » Tip Bank » C++
Language: C++
Expertise: Intermediate
Mar 1, 2000



Building the Right Environment to Support AI, Machine Learning and Deep Learning

A Universal Data Format

Data types larger than the size of a byte aren't portable because of the different endian-ordering of each hardware architecture. This means that passing an int in its binary form from an Intel-based machine to a Unix machine or vice versa requires that you reverse the integer's byte before the target machine can read it. Sometimes, reversing the byte ordering is either too expensive in terms of performance or it's simply too complicated. Worse yet, there are several ordering options: little endian, big endian, middle endian and so on. It's not always possible to predict the exact byte ordering of the target machine in advance. Is there a workaround? Yes, there is. Pass all data variables in their textual representation. For example, instead of passing the integer 0 as a sequence of 4 bytes, pass the string "0". Another example: instead of passing the integer 32 as a sequence of the bytes 0x0, 0x0, 0x0, 0x20, pass the literal string "32" instead. Char arrays are portable and they do not require order reversing.
Danny Kalev
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date