Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

a curly one

Status
Not open for further replies.

rotovegasBoy

Programmer
Sep 16, 1999
88
NZ
We're using some code that needs to take a 64 bit timestamp value and use 36 bits of it. Heres the situation.
The 64 bit value is read from hardware into two 32bit variables upper and lower we want to discard the 4 least significant bits of lower and shift the number 4 bits to the left. this is added to the 4 least significant bits of upper which have been shifted right 28 bits so the resultant number looks like this:
0xULLLLLLL. theres the code wee're using now

/*assume upper and lower have been loaded correctly and declared*/

lower = lower >> 4;
upper = upper << 28;
result = lower + upper;

return result;

Is there anything immediately wrong with this code?
Also we cant just use a long data type because its on an embedded system with a propreitry OS and the biggest data type is unsigned 32bits.

Thanks X-)
Chris Packham
If a tree falls in the woods and it hits Bill Gates does anyone care?
 
Can you print values of your 64 bit data and
upper and lower before shifting.
 
One error is:
result = lower+upper;
you should use:
result = lower|upper;
Other errors deppends on context. I'm not sure if I understand correct other errors, but shift left is <<, shift right >>.
result of >> deppends on, is variable signed or no and if signed is negative or not. This operator is ambiguos:
unsigned int x=((unsigned int)-1)>>4;
is different than:
unsigned int x=(unsigned int)((signed int)-1)>>4;
In java exists an other operator >>>. John Fill
1c.bmp


ivfmd@mail.md
 
Bit of clarification all the numbers used are unsigned, and no i cant print out the values because its in a kernel routine so if i printed them out i'd get a whole heap of mess.
Chris Packham
If a tree falls in the woods and it hits Bill Gates does anyone care?
 
looks like it was a compiler optimisation thing that had more to do with registers than it did with shifting.
thanks
Chris Packham
If a tree falls in the woods and it hits Bill Gates does anyone care?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top