B4J Question The Bits are Byting me in the ass!

Kevin

Well-Known Member
Licensed User
I never did quite grasp the concept of bits. I am trying to decode date and time stamps that are stored as follows:

Date is specified in decimal 16-bit integer in the following formats:

Bit 15-9
Year: Specify a value based on 0 as a 1980.

Bit 8-5

Month: Specify a value from 1 to 12.

Bit 4-0
Day: Specify a value from 1 to 31.


Time is specified in decimal 16-bit integer in the following formats:

Bit 15-11
Hour

Bit 10-5
Minute

Bit 4-0
Second / 2



So how can I work this out? This is all I have (actual sample values), which arguably is really nothing. :(

B4X:
Dim iDateStamp as Int = 18026
Dim iTimeStamp as Int = 24577

??????????
 

Kevin

Well-Known Member
Licensed User
I have no idea what the hex parts are doing, but I will give it a shot. Thanks!!!
 

Kevin

Well-Known Member
Licensed User
Aha! Thanks for the further explanation. With that I managed to get the month part right!

B4X:
Dim Month as Int = Bit.ShiftRight(Bit.And(iDateStamp, 0xFF), 5)
I'll likely forget this by tomorrow but at least I can refer myself back to this thread. Thanks again! :D
 
Top