Question

2. On the Arduino Uno (and other ATMega based boards) an “int” stores a 16-bit (2-byte)...

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.

a-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?

b-How is -128 stored in Arduino Uno using the 2’s complement notation?

Homework Answers

Answer #1

a. Binary integers can be in the range of -2?15 i.e. (1000000000000000)?2 to +(215? - 1) i.e (0111111111111111)?2. Hence in decimal it turns out to be -32768 to +32767. In Hex directly read binary value in group of 4 from LSB direction i.e. 0x8000

b. First represent +128 in binary form and then take 2s complement along with sign bit as 1 to represent negative number.

Hence +128 = (010000000)2? , and its two's complent will be 101111111 + 1 = 110000000

Now Sign extend to have 16 bit number for Arduino Uno Compatability. So -128 = (1111111110000000)?2

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions