| Both sides previous revisionPrevious revisionNext revision | Previous revision |
| en:multiasm:cs:chapter_3_11 [2026/02/08 17:31] – [Integers] ktokarz | en:multiasm:cs:chapter_3_11 [2026/03/29 18:24] (current) – [Endianness] ktokarz |
|---|
| |
| ===== Integers ===== | ===== Integers ===== |
| Integer data types can be 8, 16, 32 or 64 bits long. If the encoded number is unsigned, it is stored in binary representation, while if the value is signed, the representation is two's complement. A natural binary number range starts with zero. In such a case, it contains all bits equal to zero. While it contains all bits equal to one, the value can be calculated with the expression {{ :en:multiasm:cs:equation_binary.png?100 |}}, where n is the number of bits in a number. | Integer data types can be 8, 16, 32 or 64 bits long. If the encoded number is unsigned, it is stored in binary representation, while if the value is signed, the representation is two's complement. A natural binary number range starts with zero. In such a case, it contains all bits equal to zero. While it contains all bits equal to one, the value can be calculated with the expression\\ |
| | {{:en:multiasm:cs:equation_binary.png?100 |}},\\ \\ |
| | where n is the number of bits in a number. |
| |
| In two's complement representation, the most significant bit (MSB) represents the sign of the number. Zero means a non-negative number; one represents a negative value. The table {{ref>binarynumbers}} shows the integer data types with their ranges. | In two's complement representation, the most significant bit (MSB) represents the sign of the number. Zero means a non-negative number; one represents a negative value. The table {{ref>binarynumbers}} shows the integer data types with their ranges. |
| * Exponent (E) | * Exponent (E) |
| * Mantissa (M) | * Mantissa (M) |
| fulfilling the equation | fulfilling the equation\\ |
| {{ :en:multiasm:cs:equation_floating.png?200 |}} | {{:en:multiasm:cs:equation_floating.png?100 |}}.\\ |
| |
| There are two main types of real numbers, called floating-point values. Single precision is a number which is encoded in 32 bits. A double-precision floating-point number is encoded with 64 bits. They are presented in Fig{{ref>realtypes}}. | There are two main types of real numbers, called floating-point values. Single precision is a number which is encoded in 32 bits. A double-precision floating-point number is encoded with 64 bits. They are presented in Fig{{ref>realtypes}}. |
| |
| <figure realtypes> | <figure realtypes> |
| {{ :en:multiasm:cs:floating_numbers.png?600 |Illustration of a single and double precision real numbers}} | {{:en:multiasm:cs:floating_numbers.png?600 |Illustration of a single and double precision real numbers}} |
| <caption>Illustration of a single and double precision real numbers </caption> | <caption>Illustration of a single and double precision real numbers </caption> |
| </figure> | </figure> |
| <table realnumbers> | <table realnumbers> |
| <caption> Floating point numbers</caption> | <caption> Floating point numbers</caption> |
| ^ Precision ^ Exponent ^ Mantissa ^ The smallest ^ The largest ^ | ^ Precision ^ Exponent ^ Mantissa ^ The smallest ^ The largest ^ |
| | Single (32 bit) | 8 bits | 23 bits | {{ :en:multiasm:cs:min_fp_32.png?105 }} | {{ :en:multiasm:cs:max_fp_32.png?100 }} | | | Single (32 bit) | 8 bits | 23 bits | {{ :en:multiasm:cs:min_fp_32.png?50 }} | {{ :en:multiasm:cs:max_fp_32.png?50 }} | |
| | Double (64 bit) | 11 bits | 52 bits | {{ :en:multiasm:cs:min_fp_64.png?120 }} | {{ :en:multiasm:cs:max_fp_64.png?100 }} | | | Double (64 bit) | 11 bits | 52 bits | {{ :en:multiasm:cs:min_fp_64.png?60 }} | {{ :en:multiasm:cs:max_fp_64.png?50 }} | |
| </table> | </table> |
| |
| <caption>Illustration of Little and Big Endian data placement in the memory</caption> | <caption>Illustration of Little and Big Endian data placement in the memory</caption> |
| </figure> | </figure> |
| | |
| | Big-endian is mainly used in network protocols, where the most significant bytes are sent first. In modern processors, the dominant order of data placement in memory is little-endian, although some processors (including ARM) can support both modes. Big endian is more human intuitive, but little endian makes it possible to access the same data with different sizes at the same address. It is important for fast data type casting (for example, treating a 32-bit integer as a 16-bit integer) because the starting address doesn't change. Some processors support conversion between little- and big-endianness with special instructions. |