Is there any middleware/library that will convert your binary or text data from 64-bit to 32-bit?

387 Views Asked by At

We use C++ in both front-end (Windows 32-bit) and back-end (Linux 64-bit). They can pass either binary or text data to communicate. Is there any middleware/library that will convert these data from 64-bit to 32-bit? Or is the only option to change your code?

1

There are 1 best solutions below

1
On

There's no such thing like "64-bit text data". A text file just contains characters in some encoding. And currently there's no 64-bit encoding available. The longest fixed-width encoding is UTF-32 which is 32-bit long. For variable-length encoding, it's maximum 6-byte long for UTF-8 (edit: it has been officially limited to 4 bytes only because the range for Unicode was restricted to U+10FFFF) and a different number for others, but none is up to 8 bytes long. If there are differences then you need to convert the encoding, not 64-bit to 32-bit

For more information read The Absolute Minimum Every Software Developer Absolutely, Positively Must Know About Unicode and Character Sets (No Excuses!)


Binary is also just a series of bits, not necessary an array of constant width 64-bit or 32-bit numbers although in modern computer architectures the size is a multiple of bytes. You need to read the data exactly like how they were written. If you write a 64-bit value, read as a 64-bit value regardless of the 16, 32 or 64-bit program. How can you ensure that a number written in 64-bit does not overflow when cropping to 32-bit?

If you're using MSVC then the type sizes are the same in both 32 and 64-bit mode except pointers, thus no code changing is required if you stick to the standard. On most other 64-bit platforms you may need to take care if you use long since it's wider than in a 32-bit program.

It's better to use C++11's standard types like intN_t in cstdint in cross-platform code. Before C++11 and C99 many libraries and compilers also define their own standard fixed-width integer types like that for compatibility, for example qint32 in Qt and __int32 in MSVC