Hi
I'd like to write files with binary content (.vtk)
I need to put to file some data-points.
I know that inside file should I get (I know because I compared with some other correct written .vtk files):
3F 80 00 00 40 00 00 00
what means points = 1 , 2
but when I write myself :
Code:
float zma;
zma = 1;
fwrite(&zma, sizeof zma, 1, file_with_points);
i got: >> 00 00 80 3F 00 00 00 40
Thats big and Little Endian Byte Order problem.
So I wrote function to change byte order.
Code:
signed int LE_2_BI(signed int num)
{
signed int wynik = 0x00000000, maska1= 0xFF, maska2= 0xFF00,
maska3= 0xFF0000, maska4= 0xFF000000,
liczba1, liczba2, liczba3, liczba4;
liczba1 = num & maska1;
liczba1 = liczba1 << 24;
liczba2 = num & maska2;
liczba2 = liczba2 << 8;
liczba3 = num & maska3;
liczba3 = liczba3 >> 8;
liczba4 = num & maska4;
liczba4 = liczba4 >> 24;
wynik = liczba1 | liczba2 | liczba3 | liczba4;
printf ( "num=%08x\n wynik=%08x\n", num, wynik);
return wynik;
};
use function
Code:
float data1;
float zma;
zma = 1;
data1 = LE_2_BI(*(int *)&zma);
fwrite(&data1, sizeof data1, 1, file_with_points);
result 00 3F 00 47 :-(
Why ??
How can I write correct byte order into the file?
Daniel