This commit is contained in:
Miloslav Ciz 2025-01-19 14:26:24 +01:00
parent 70c10acfc5
commit 1f6026b2ee
26 changed files with 1965 additions and 1903 deletions

View file

@ -1,6 +1,6 @@
# Byte
Byte (symbol: B) is a basic unit of [information](information.md), nowadays already practically always consisting of 8 [bits](bit.md) (for which it's also called an **octet**), that allow it to store 2^8 = 256 distinct values (for example a number in range 0 to 255). It is commonly the smallest unit of computer memory a [CPU](cpu.md) is able to operate on; memory addresses are assigned by steps of one byte. We use bytes to measure the size of [memory](memory.md) and derive higher memory [units](memory_units.md) such as a kilobyte (kB, 1000 bytes), kibibyte (KiB, 1024 bytes), megabyte (MB, 10^6 bytes) and so forth. In conventional [programming](programming.md) a one byte [variable](variable.md) is seen as very small and used if we are really limited by memory constraints (e.g. [embedded](embedded.md)) or to mimic older 8bit computers ("[retro](retro.md) games" etc.): one byte can be used to store very small numbers (while in mainstream processors numbers nowadays mostly have 4 or 8 bytes), text characters ([ASCII](ascii.md), ...), very primitive [colors](color.md) (see [RGB332](rgb332.md), [palettes](palette.md), ...) etc.
Byte (symbol: B) is a basic unit of [information](information.md), now practically always consisting of 8 [bits](bit.md) (for which we also use the term **octet**), which allow storing 2^8 = 256 distinct values (for example a number in range 0 to 255). This is commonly the smallest unit of computer memory a [CPU](cpu.md) is able to operate on; memory addresses are assigned by steps of one byte. We use bytes to measure the size of [memory](memory.md) and derive higher [units](memory_units.md) such as a kilobyte (kB, 1000 bytes), kibibyte (KiB, 1024 bytes), megabyte (MB, 10^6 bytes) and so forth. In conventional [programming](programming.md) a one byte [variable](variable.md) is seen as very small and used mostly when we find ourselves pressured by tight memory constraints (e.g. [embedded](embedded.md)) or to mimic older 8bit computers ("[retro](retro.md) games" etc.): one byte can be used to store very small numbers (while in today's mainstream processors basic numbers usually consist of 4 or 8 bytes), text characters ([ASCII](ascii.md), ...), very primitive [colors](color.md) (see [RGB332](rgb332.md), [palettes](palette.md), ...) etc.
Historically *byte* was used to stand for the basic addressable unit of memory capable of storing one text character or another "basic value" and could therefore have a different size than 8 bits: for example ASCII machines might have had a 7bit byte, 16bit machines a 16bit byte etc.; in [C](c.md) (standard 99) `char` is the "byte" data type, its byte size is always 1 (`sizeof(char) == 1`), though its number of bits (`CHAR_BIT`) can be greater or equal to 8; if you need an exact 8bit byte use types such as `int8_t` and `uint8_t` from the standard `stdint` library. From now on we will implicitly talk about 8bit bytes.