so 10001011000 and 0000010001011000 would be uint8 and uint16 bit representations of 1112.
And the upper bits would keep getting zeros as long as the size of the datatype extends further as uint32 and uint64 right for this value(1112) as an example?
2. We want to save the number of Step-1 into memory locations of the ATmega328P MCU of the Arduino UNO Board. One memory location of the MCU holds 8-bit data. How many memory locations do we need to store 1112? By hand calculation, we find that 1112 turns to be 10001011000 in bit form. There are 11-bit data; so need about 1.375 memory locations to save the 11-bit binary data. Because there is no way to accept fractional memory locations such as 1.375, we must accept two consecutive memory locations. The lower 8-bit (01011000) of the 11-bit data will be saved into the 1st memory location; the upper 3-bit (100) data will be transformed into 8-bit data after appending five 0s to its left (00000100) and then the resultant 8-bit number (00000100) will be saved in the next high order memory location.
3. Now, we need to make a request to the Compiler to allocate 16-bit (2-byte) memory space for us to store the number of Step-2. The request is made by the following declaration:
unsigned int x = 0b0000010001011000;
or
unsigned int x = 0x0458; //hex representation of 1112
or
unsigned int x = 1112; //the Compiler automatically saves 00000100 01011000 into memory
or
uint16_t x = 1112;
What is the difference between these two styles: 'unsigned int' and 'uint16_t'? Please, make a search at the net.
4. We may execute the following codes to see what has been exactly saved into memory locations in response to this declaration: unsigned int x = 1112;.
void setup()
{
Serial.begin(9600);
unsigned int x = 1112;
for (int i = 15; i >= 0; i--) //shows: 00000100 01011000
{
bool n = bitRead(x, i);
if (n == 0)
{
Serial.print('0'); //forcibly showing 0 as Serial Monitor does not show leading 0s
}
else
{
Serial.print(n, BIN);
}
}
}
void loop()
{
}