954,496 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Problem regarding storing value into unsigned int

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; // It may be a global variable
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 into 'c' and 'd', which is not a problem in case of storing that value into 'b'.
If you provide the answer using 4 unsigned integer (16 bit each) variable, it is also somhow acceptable.
Note: a' is a global variable. and 'c' and 'd' 'll also be global.
Thanks to all.

ariyan
Newbie Poster
4 posts since Sep 2006
Reputation Points: 13
Solved Threads: 0
 

I think you can use shifting and bitwise operators.

Grunt
Junior Poster
152 posts since Jul 2006
Reputation Points: 197
Solved Threads: 12
 

I'd agree with Grunt. But to make my post somewhat meaningful, I though I'd also point out that you made b of type unsigned long double . I'm thinking that you don't want a floating point value if you're doing integer operations (especially if you're using bitwise operators).

Infarction
Posting Virtuoso
1,580 posts since May 2006
Reputation Points: 683
Solved Threads: 53
 

and I think unsigned long double is anyway wrong.

Grunt
Junior Poster
152 posts since Jul 2006
Reputation Points: 197
Solved Threads: 12
 

Yeah, IIRC floating point values are always signed. I think some compilers accept long double as a type though. The OP probably meant to use unsigned long long , I'm guessing.

Infarction
Posting Virtuoso
1,580 posts since May 2006
Reputation Points: 683
Solved Threads: 53
 
I'd agree with Grunt. But to make my post somewhat meaningful, I though I'd also point out that you made b of type unsigned long double . I'm thinking that you don't want a floating point value if you're doing integer operations (especially if you're using bitwise operators).



yeah you are right. I can do that job by using double, but I am unable to use that in my environment. I have to usec either 'long' o 'int'.

ariyan
Newbie Poster
4 posts since Sep 2006
Reputation Points: 13
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You