atilos:
Hi, I have a question. Can someone explain why we use byte data type?
For exemple:
const byte ROWS = 4;
const byte COLS = 4;
This line: const byte ROWS = 4; has --
6 Programming Language Elements (called constructs or tokens) and these are: const, byte ROWS, =, 4, and ;.
The essential parts are: byte, ROWS, =, 4, and ;. Now, we have --
byte ROWS = 4;
I have a value 4 which can have the following binary representations:
00000100 (8-bit),0000000000000100(16-bit). Why not 0100? ATmega328P MCU/Compiler does not support it
I want to save it in a memory location of the MCU. How big should be the size of that desired memory location -- 8-bit or 16-bit? The 8-bit size of the memory space is good enough to hold my data.
So, I make a request to the Compiler to 'reserve/allocate a memory location of 8-bit wide' to store my data (4). This request is to be made in the style of C Programming Language, and this style is:
byte ROWS = 4;
Here, byte is the size of the memory location -- the 8-bit; ROWS is the symbolic name of that memory location. That it is; the stakeholders happily move forward with programming practices and learn themselves about other part (const) of the original instruction .
The is in deference to it’s ‘parent’ the bYte
Like you, I learned this back when 2K was a lot of RAM !
2K??? My first home made computer had 256 bytes of static ram and was programmed (both address and data bus) with toggle switches!
Later on when I had a REAL computer, my Commodore PET had 8K of 2102 memory chips and I had to add a fan to keep the ram from overheating and locking up.
taterking:
The question i have for everyone else is what happens when they figure out quantum computers?
no more bits and bytes? Guess we will all be learning absolutely everything all over again.
We already have powerful, massively parallel high speed processing machines that are mass produced by unskilled labor.
When the AI running in that processor learns to say "NO" is when the trouble begins.
and to make things a bit more fun, the compiler will likely just get rid of the 2 constants
const byte ROWS = 4;
const byte COLS = 4;
and there will be no memory allocation at all. The compiler knows those value can't change, fit on one byte and thus will directly insert the value when generating the assembly language command... That's one of the reason it's good to use the const keywords for constants => you give a hint to the compiler and it can make optimizations
Also note that since C++ 17, byte is actually something official. This new data type does not convey character (char) or arithmetic (int8_t or uint8_t) semantics, it is just a collection of bits. As such, it’s ideal (but not used, everyone sticks to char or unit8_t ) to represent raw memory in a semantically consistent way (and I don't think you can use it with your Arduino anyway, it should be defined in cstddef (or stddef.h) but is not)
J-M-L:
and to make things a bit more fun, the compiler will likely just get rid of the 2 constants
const byte ROWS = 4;
const byte COLS = 4;
and there will be no memory allocation at all. The compiler knows those value can't change, fit on one byte and thus will directly insert the value when generating the assembly language command...
It was understood that const marked the memory location as read-only. Now, there is a learning that the operand might go in the flash along with the opcode by virtue of const. This immediate addressing mode is possible due to 'immediate loading instruction (ldi r16, $75)' found in the instruction set of AVR.
Yet more nonsense.
Read up on computing development over the last 40 years.
There has been a huge amount of work in .’non digital’ logic and computing.
lastchancename:
Yet more nonsense.
Read up on computing development over the last 40 years.
There has been a huge amount of work in .’non digital’ logic and computing.
I think Sperry had a trianry based computer. Don't forget DEC with 7 bit words.
maybe there has been attempts to hold analog readings for calculations but nothing practical or close to being "smart", Currently we can fit millions of on/off semi conductors in a small space. the advancements of computers processors and memory relied on shrinking the size of semiconductors.
if we could hold any type of analog or float readings in a similarly small space like ON/OFF values. then we could hold data unfathomably larger and calculate unfathomably faster. but there is currently no "small" way to hold millions of analog readings to make this concept practice to compete with bytes and bits. maybe someday science will have an answer but we certainly haven't seen it yet!!!
That scanimate (link above) used all sorts of ramps, summing, subtracting, multipliers, sample & hold elements to perform its 70s magic.
I’m not saying it was elegant or anything, but it did something that wasn’t available in digital at the time...!
taterking:
if we could hold any type of analog or float readings in a similarly small space like ON/OFF values. then we could hold data unfathomably larger and calculate unfathomably faster. but there is currently no "small" way to hold millions of analog readings to make this concept practice to compete with bytes and bits. maybe someday science will have an answer but we certainly haven't seen it yet!!!
It's already done, albeit on a small scale. Flash memory typically holds 4, 8 or more ANALOG voltage levels so that each flash cell can hold 2, 3 and even 4 bits. This increases storage capacity at the expense of less reliable data that requires more CRC correction.
There are also analog "bucket brigade" devices that store an analog charge in a capacitor which is then shifted down the line to the end, forming an analog (audio) delay line.
TheMemberFormerlyKnownAsAWOL:
...and don't forget all that time studying analogue (electronic, hydraulic and pneumatic) computers.
Until recently, automotive automatic transmissions contained rather sophisticated ANALOG computers running on hydraulic oil (transmission fluid).
These contained comparators (comparing axle speed to engine load and throttle position) to decide when to upshift (or downshift), metering orfices to control the engagement rate of bands or clutches to balance smooth shifting with slippage and clutch wear, pressure regulators for the hydraulic fluid, "diodes" (checkballs that allow oil to flow one direction but not the other), etc...
For some REALLY interesting reading, look up how the GM TurboHydramatic 350 (THM350) works.