|
I am reading a bunch of binary data and extracting a time array (5bytes). I store them in a Nx5 array of uint8 class.
The data if viewed in hex would look like this:
HHMM SSss ss (Day Hour Min Sec. sec)
so an example starting at 12:01:12.3456 (0.001 sec increments)
..... in Hex ...
12 01 12 34 56
12 01 12 34 66
12 01 12 34 76
.... in decimal ....
18 01 18 52 86
18 01 18 52 102
18 01 18 52 118
.......
I am currently "decoding" the BCD to its real decimal equivalent in the following way using bitshift and bitand. Then converting to seconds of the day
% T is time array (nx6) uint8
h = bitshift(T(:,1),-4)*10 + bitand(15,T(:,1));
m = bitshift(T(:,2),-4)*10 + bitand(15,T(:,2));
s = bitshift(T(:,3),-4)*10 + bitand(15,T(:,3)) + bitshift(T(:,4),-4)*.1 + bitand(15,T(:,4))*.01 + bitshift(T(:,5),-4)*.001 + bitand(15,T(:,5))*.0001 ;
TotalSec = h*3600+m*60+s;
So my question is ...Is there an easier way to go from BCD to Decimal.
|