Jeetdesai
Joined: 05 Jul 2018 Posts: 18
|
Adding 8-bit integers and storing the result in an 8-bit int |
Posted: Fri Jan 11, 2019 11:58 am |
|
|
If I add three 8-bit integers, how will the result be saved in an 8-bit integer.
Eg:
Code: |
#use RS232(BAUD=9600, XMIT=PIN_B6, RCV=PIN_B7, FORCE_SW)
int8 high_byte = 200;
int8 low_byte = 150;
int8 element = 100;
int8 sum = 0;
void main()
{
sum = high_byte + low_byte + element ;
putc(sum);
} |
I know this is not the ideal situation and when two or more 8-bit integers are added, there is a possibility of the result to exceed 255 and thereby requiring a 16-bit integer to store the result.
But what if the result or sum is placed in an 8-bit integer? Will the carry bits be avoided? or will it store random data? |
|