ernest
Joined: 11 Feb 2004 Posts: 51
|
Arithmetric Addition for 32-bit integer |
Posted: Thu Apr 08, 2004 7:50 pm |
|
|
I am trying to perform arithmetric addition for integers of more than 16-bits. The following is the code that I use but it does not allow SUM of variable 'a' and 'b' that exceed 16-bits ie. less than 65536 only.
What shall I do to allow it to calculate the SUM of more than 16-bit say 32 bits?
Cheers...
#include <16f877a.h>
//#device ICD=TRUE
#fuses HS,NOLVP,NOWDT,PUT
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
#include <utility.c>
#include <stdlib.h>
#include <input.c>
#define GREEN_LED PIN_A5
#define YELLOW_LED PIN_B4
#define RED_LED PIN_B5
#define PUSH_BUTTON PIN_A4
main()
{
int32 a,b,result;
char opr;
int8 digits[7];
signed int8 counter;
int32 val;
int16 low;
int16 high;
setup_timer_0(RTCC_INTERNAL);
while(TRUE)
{
printf("\r\nEnter the first number: ");
a=get_long();
do
{
printf("\r\nEnter the operator (+-*/): ");
opr = getc();
}
while(!isamoung(opr,"+-*/"));
printf("\r\nEnter the second number: ");
b = get_long();
switch(opr)
{
case '+':
result = a + b;
break;
case '-':
result = a - b;
break;
case '*':
result = a * b;
break;
case '/':
result = a / b;
break;
}
/////////////////////////////////////////////////////////////////
val = a;
for (counter=7;counter>-1;counter--)
{
digits[counter]=val%10;
val=val/10;
}
low=result % 1000L;
high=result / 1000L;
printf("\r\nThe result is %lu%lu ",high,low);
// printf("\r\nVal= %d %d %d %d %d %d",digits[0],digits[1],digits[2],digits[3],digits[4],digits[5],digits[6]);
}
} |
|