Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

How to store a 64 bit value into 2 unsigned long variables?

Status
Not open for further replies.

ariyan

Member level 5
Joined
Aug 24, 2006
Messages
81
Helped
4
Reputation
8
Reaction score
2
Trophy points
1,288
Activity points
1,804
'C' help needed

How to store a 64 bit value into 2 unsigned long variable (of 32 bit)?

Let,

unsigned long a; // variable 'a' will be incremented regularly and 'll be stored in b
void fun(void)
{
unsigned long double b;
b += a; // if b is a 64 bit variable ,
// regular addition of 'a' into 'b' will increase the value greater than 32 bit
};

Now instead of using variable b of using 64 bit, I have to use two unsigned long variable(let c, d of 32 bit each) and store the value in a into c and d, which is not a problem in case of storing that value into 'b'.
 

Re: 'C' help needed

Hi

You can use UNION to share data variables

All the best

Bobi
 

Re: 'C' help needed

Or...

extern unsigned long a;

unsigned long c = 0UL;
unsigned long d = 0UL;

void fun(void)
{
/* check overflow for c += a */
if ( (0xFFFFFFFFUL - a) <= c )
{
d += 1;
}

/* overflow is ignored now */
c += a;

/* example: use of the 'big' number */
{
unsigned long double big_number;
big_number = ((unsigned long double) d)<<32 + c;
}
}
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top