+ 1

What are but and bytes. What's their purpose ? Why should we use float and double and int and unsigned and signed int for it ?

Bit an bytes purpose ? C++

27th Jun 2019, 3:36 PM
The unknown 321
The unknown 321 - avatar
7 Antworten
+ 4
A bit is a unit of memory. It’s a one or zero. 8 bits is 1 byte. If I have a number like 794 or something, I just say int a = 794, which allocates a memory space of 4 bytes for 794. But if I have a huge number like a billion, I want to allocate 8 bytes to store the number with double int a = 1,000,000,000. https://code.sololearn.com/c8RzXXV60t09/?ref=app
27th Jun 2019, 3:58 PM
Pete Cowling
Pete Cowling - avatar
+ 1
But what's the purpose of knowing this thing ? I mean I can know the size of my program with this thing ?
27th Jun 2019, 4:09 PM
The unknown 321
The unknown 321 - avatar
+ 1
Knowing the sizes of data types can give you basic knowledge about programming. At least you will know which data type is appropriate. In example, you want to have an array of numbers and every numbers holds value between -100 and 100. Instead of using int, you can use signed char. It will save more spaces. Another example is when you want to have a calculations which involve fractional number. Double and float have to be used for this calculation. However, double has the size of 8 bytes which is twice larger than float. It means that it consumes more space but more precise. Knowing this you'll know whether you want to use float or double
27th Jun 2019, 4:27 PM
Agent_I
Agent_I - avatar
+ 1
So this thing is related to the memory of the computer and related to the mb and gb etc ?
27th Jun 2019, 4:31 PM
The unknown 321
The unknown 321 - avatar
+ 1
Yes
27th Jun 2019, 4:34 PM
Agent_I
Agent_I - avatar
+ 1
Oh ok. Thanks for the explanation
27th Jun 2019, 4:34 PM
The unknown 321
The unknown 321 - avatar
+ 1
Electronics factor: All computers, digital electronic devices, and anything that has made up of transistors (imagine a water valve) are only operable with two levels of voltage. One indicates the transistor is "on" or "high" or "1" (e.g for a standard TTL between 2V - 5V) and other indicates it is "off" or "low" or "0" (between 0V - 0.8V). So, essentially, all building blocks of a computing system (from hardware to software) are operating based upon this unchangeable foundation. Digital circuitry and CPU: In the heart of every digital computer is the Central Processing Unit (CPU) which is responsible for processing data, coordinating devices, and many other things. Inside a CPU, billions of transistors in the form of the Arithmetic Logic Unit (ALU) which performs simple arithmetic and logical operations, Control Unit (CU) which coordinates the various components of the computer, Memory Management Unit (MMU), etc are making it possible that all kinds of software from the operating system to computer games be able to be used. All of those units only understand two things: 0 and 1 (i.e bit) on its very nature. Data communication and storage: A byte is a unit of digital information that most commonly consists of eight bits (Wikipedia). It also represents the size of a single character. On a regular digital computer, the smallest addressable/storable unit of data is consists of 1 byte. The larger units are 2, 4, 8, 16, ... bytes. Data, information, and programming: A computer program is usually composed of "data" and "code". Data is some entity which needs to be processed and become meaningful information. For example, the radius of a circle represents a data and after processing by the "code" it may produce the circle's area which is considered a piece of meaningful information. Programming languages provide some sort of data types with different property like size, representable format, alignment on memory, etc. by which the programmer can decide which one is best for the purpose of his/her project.
27th Jun 2019, 4:55 PM
To Seek Glory in Battle is Glorious
To Seek Glory in Battle is Glorious - avatar