Hi guys, I am writing a vector into a binary file (linux of course), but somehow there seems to be something wrong with this code, because the output file size in binary is BIGGER than doing it with the same vector but insead of binary, in plain text, and I as far as I understand, binary files size it's lesser than saving it as a text.
Also, being unable to read it from linux command line makes things difficult (I can't see if it wrote the numbers since I do not know any command that would read the file made ).
Yes, but realize that in x86 and other systems, integers and floats are little-endian, so a short of 258 is hex 0201, whereas in SPARC and other big-endian systems, and in Internet packet headers, it is hex 0102.
Second, "#pragma pack" tells the compiler what modulus to allocate storage on, so if you write a struct or such, it may be padded.
Imagine that; you get four binary bytes representing the integer 32. Because this is a little-endian system, they end up all backwards. Try echo $((0x00000020)) in your shell.
It is.
They are numbers. Binary numbers.
---------- Post updated at 09:14 AM ---------- Previous update was at 09:08 AM ----------
'int' types are 32-bit even on most 64-bit systems. long integers, though, are generally 64-bit on 64-bit systems (and 32-bit elsewhere). And if your system is neither 32 nor 64 bits, all bets are off.
If you're concerned about your integers changing size when your code gets moved, you can #include <stdint.h> and use int32_t to get a 32-bit integer that'll always be a 32-bit integer.