Ashu
Ashu

Reputation: 1733

Java: How to replace last 18 bits of a long

I am getting last 18 bits (to save space) of a UTC timestamp from sensors. Not on my side I want to generate the complete UTC time from those 18 bits by replacing the last 18 bits of current timestamp with the one I am getting from Sensors. Any help will be appreciated.

Upvotes: 0

Views: 86

Answers (1)

Oleg
Oleg

Reputation: 6314

currentStamp &= ~0x3FFFF; // Set the last 18 bits to 0
sensorStamp &= 0x3FFFF; // Set all except the last 18 bits to 0
currentStamp |= sensorStamp; // combine

Upvotes: 2

Related Questions