What is the difference between large and small chests?

For integer values, this is quite simply the difference in representing the small end and the large end.

But for me it’s not entirely clear how a small floating-point chest differs from a large floater.

And finally, I would like to know what is more commonly used.

+6
source share
2 answers

Some sources claim that the IEEE754 floats are always kept little, but the IEEE754 specification for floating point numbers simply does not cover the problem of enditality and can vary from machine to machine. Here is a sample code for converting floating point / byte arrays:

#include <stdio.h> int main(int argc, char** argv){ char *a; float f = 3.14159; // number to start with a = (char *)&f; // point a to f location // print float & byte array as hex printf("float: %f\n", f); printf("byte array: %hhX:%hhX:%hhX:%hhX\n", \ a[0], a[1], a[2], a[3]); // toggle the sign of f -- using the byte array a[3] = ((unsigned int)a[3]) ^ 128; //print the numbers again printf("float: %f\n", f); printf("byte array: %hhX:%hhX:%hhX:%hhX\n", \ a[0], a[1], a[2], a[3]); return 0; } 

It is displayed on a Little Indian machine:

float: 3.141590 byte array: D0: F: 49: 40 float: -3.141590 byte array: D0: F: 49: C0

Theoretically, on a large-end machine, the byte order would be reversed.

Link: http://betterexplained.com/articles/understanding-big-and-little-endian-byte-order/

+6
source

Endianness is simply a property of bytes that make up a value consisting of several bytes. Since the floating point number is 4 or 8 bytes, you indicate in which order to read them. This is exactly the same as with integer values.

+11
source

Source: https://habr.com/ru/post/907173/


All Articles