[SOLVED] how to perform an operation on value greater then 65535?

Status
Not open for further replies.

uday mehta

Advanced Member level 4
Joined
Dec 30, 2011
Messages
104
Helped
6
Reputation
12
Reaction score
6
Trophy points
1,298
Activity points
1,979
i me counting something from 0 to 99999. here if i use an integer and increment it then it will reached its limit i.e. 65535. which data type i can use in this code...


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include<reg51.h>
sbit ip = P3^0;
 
void delay(unsigned int p)
{
 int i,j;
 for(i=0;i<p;i++)
 for(j=0;j<1250;j++);
}
 
void main()
{
 int val[]={0xc0,0xf9,0xa4,0xb0,0x91,0x92,0x82,0xf8,0x80,0x90};
 int a,b,c,d,e,br,cr,dr,er,x;
 a=0;
 while(1)
 {
 b=a/10000;
 br=a%10000;
 c=br/1000;
 cr=br%1000;
 d=cr/100;
 dr=cr%100;
 e=dr/10;
 er=dr%10;
 x=b;
 P1=0x80;
 P2=val[x];
 delay(10);
 x=c;
 P1=0x08;
 P2=val[x];
 delay(10);
 x=d;
 P1=0x04;
 P2=val[x];
 delay(10);
 x=e;
 P1=0x02;
 P2=val[x];
 delay(10);
 x=er;
 P1=0x01;
 P2=val[x];
 delay(10);
 while(ip==0);
 a=a+1;
 while(ip==1);
 }
 }




here i want that variable "a" reach to 99999... if i change the data type to double then "br=b%10000" gives an error.
 
Last edited by a moderator:

Sizes of data types are implementation dependend. People use to consult a compiler's user manual to know about the details. Most compilers (e.g. Keil C51) implement the type long with 32 bit size
 


for 16 bit compiler just assign as unsigned long int which 'll give you a range of 0 to 4294967296... For 32 bit compiler u can assign just as int to get the same range.

As you mention I guess you r using 16 bit compiler. So assign as unsigned long in...
 
i tried long int but first it reach to 65500 and then next time it reach to 35500(nearly). actually it is fast so i can't see exact value. but when i want to count from 00 to 999999 then it count 65500 then 35500 and add it. means whole program works fine but not display value from 65500 to 99999.
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…