Using "bytes" and "bits"

Asked

Viewed 347 times

2

What use bytes and bits?

I’m reading some C and C++ programming books that talk about bytes and I wanted to know what the use is or what these terms are for.

For example, this table below talks about bytes:

Tipo  Descrição                            Tamanho             Intervalo
char  caractere                           1 bytes -128     a 127 ou 0 a 255
Int       inteiro                             2 ou 4 bytes    -32768 a 32767 ou -214783648 a 214783647
float Ponto flutuante                     4 bytes         -1.7E38 a 1.7E38 (precisão de 6 dígitos)
double    Ponto flutuante com 2x de precisão  8 bytes         -1.7E38 a 1.7E38 (precisão de 16 dígitos)
void  vazio   0 bytes
  • 2

    "Utility"? It depends. It is only useful if you need the computer or stored data, otherwise it is useless. (speaking of computer). Now, if you want to know "what it is," the question changes a little.

1 answer

8


A bit (Binary Digit) is the smallest unit we can find in the abstraction of computation. Computers work with pulses (all of which have been in real use since the end of World War II are electric) with a status code on or off. In modern computers this is done by a higher or lower voltage. Computer logic is binary, so it is fast and accurate. Unlike the decimal that we use (based on our fingers) the binary has only two states, false or true and everything is composed through this.

Then we have base 2, and we represent all possible digits with 0 and 1. The next number would be 2 in decimal, in binary will be 10, because to represent a third number with only one extra digit. Then the next one will be 11, and then there will be 100, which is the same as 4 to decimal.

When you have 8 different digits you have a byte (in all current architectures it is so, but could have chosen another size). It was defined this way because it is a round number (programmer works thinking in binary and round numbers are 2, 4, 8, 16, 32, etc.) that meets well the needs of the main numbers. One of the reasons is that it can be used to map the characters we need to use, the one in the table ASCII, which has 128 different characters. This would give 7 digits to represent everything (2 high to 7 gives 128), rounded to 8.

There is the nomenclature of Nibble for 4 bits, but there is no real data only with this amount of bits, it is used because some things can be represented only with them, which can even be some compression and keep two values in the same byte (Binary Term)as well as we can maintain 8 different boolean values in 1 byte. In the past it has had architectures with 4 or 8 bits in each byte.

So everything we do is composed of bytes, even some types of data are already composed of a specific amount of bytes, for example an integer has 4 bytes (typically), or an extended character in UTF-16 format has 2 bytes, or a date usually has 8 bytes, or a pixel can have 1, 2, 3 or 4 bytes (the last two most common today me day) and so on. In a 4 byte integer we have 32 bits, so it’s 2 to the 32, or just over 4 billion, which is the maximum amount of different numbers that can be represented in this type.

A type of floating point has a more complex calculation, but it has 32 or 64 bits and it is possible to represent about 4 billion or 16 quintillions of different numbers, although it seems that it is more by the way it calculates this, it goes further but skips too many numbers.

Processors are better able to handle certain types of data with these formats and amount of bytes.

The minimum size we can store, handle or carry is 1 byte. In practice depending on what you do it can be at least one byte word, or even something bigger. There is a case that the minimum is 4KB. Then a type that only needs 1 bit (because it is boolean) shall be at least 1 byte.

One curiosity is that writing KB is wrong. KB would be 1000 bytes. But because we need round numbers in binary a kilo of bytes for us is 1024 bytes, and there it must be represented correctly by Kib. Of course, everyone understands that KB is 1024 and not 1000. Only then the person buys an HDD and it comes measured in KB of truth and the person thinks the manufacturer is stealing it.

Another curiosity: 1 Kib is 1024 bytes, 1 KB is 1000 bytes and 1 Kb is 1000 bits, and of course, 1Kib is 1024 bits. People exchange it wrongly.

The subject matter is simple but it gives a chapter of a book if you’re going to talk about everything, I imagine you just wanted a summary. And the site is full of extra information, as I’ve shown in some links.

Bytes are used to measure the space occupied by some data, and it will always be a set of 8 bits (true or false states). It’s an abstract term that was created to give understanding to the minimum unit of value that we actually deal with on the computer.

  • 3

    I would be grateful if someone informed me what was wrong with the answer, I thought these things were universal knowledge.

  • +1 Thank you, this is a quick and explanatory answer!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.