2. On the Arduino Uno (and other ATMega based boards) an \"int\" stores a 16-bit
ID: 2291885 • Letter: 2
Question
2. On the Arduino Uno (and other ATMega based boards) an "int" stores a 16-bit (2- byte) value. "int" store negative numbers with a technique called 2's complement math. The highest bit, sometimes referred to as the "sign" bit, flags the number as a negative number. The rest of the bits are inverted and 1 is added. The Arduino takes care of dealing with negative numbers for you, so that arithmetic operations work transparently in the expected manner (i)What is the range of binary integers that can be stored on the Arduino Uno? What are the corresponding ranges in decimal and hexadecimal notation? (ii)How is -128 stored in Arduino Uno using the 2's complement notation?Explanation / Answer
Answer :- i) Since Uno has 16-bit value and MSB as sign, so the range in binary is-
1 000 0000 0000 0000 to 0 111 1111 1111 1111. Where 1 denotes negative sign and 0 denotes positive sign.
In decimal, it would be-
-32768 to 32767.
In Hexadecimal, it would be-
0x8000 to 0x7FFF.
Answer :- ii) -128 would be stored as-
1 111 1111 1000 0000
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.