Path: news.mathworks.com!not-for-mail
From: "Ben" <basburywvu.nospam@hotmail.com>
Newsgroups: comp.soft-sys.matlab
Subject: BCD to Decimal Conversion
Date: Thu, 6 Nov 2008 02:41:02 +0000 (UTC)
Organization: Orbital Sciences Corp
Lines: 23
Message-ID: <getlfu$eja$1@fred.mathworks.com>
Reply-To: "Ben" <basburywvu.nospam@hotmail.com>
NNTP-Posting-Host: webapp-02-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1225939262 14954 172.30.248.37 (6 Nov 2008 02:41:02 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Thu, 6 Nov 2008 02:41:02 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 425457
Xref: news.mathworks.com comp.soft-sys.matlab:499224


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.