<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/238751</link>
    <title>MATLAB Central Newsreader - BCD to Decimal Conversion</title>
    <description>Feed for thread: BCD to Decimal Conversion</description>
    <language>en-us</language>
    <copyright>&amp;copy;1994-2012 by MathWorks, Inc.</copyright>
    <webmaster>webmaster@mathworks.com</webmaster>
    <generator>MATLAB Central Newsreader</generator>
    <docs>http://blogs.law.harvard.edu/tech/rss</docs>
    <ttl>60</ttl>
    <image>
      <title>MathWorks</title>
      <url>http://www.mathworks.com/images/membrane_icon.gif</url>
    </image>
    <item>
      <pubDate>Thu, 06 Nov 2008 02:41:02 -0500</pubDate>
      <title>BCD to Decimal Conversion</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/238751#609301</link>
      <author>Ben </author>
      <description>I am reading a bunch of binary data and extracting a time array (5bytes).  I store them in a Nx5 array of uint8 class.&lt;br&gt;
&lt;br&gt;
The data if viewed in hex would look like this:&lt;br&gt;
HHMM SSss ss (Day Hour Min Sec. sec) &lt;br&gt;
so an example starting at 12:01:12.3456 (0.001 sec increments)&lt;br&gt;
..... in Hex ...&lt;br&gt;
12 01 12 34 56&lt;br&gt;
12 01 12 34 66&lt;br&gt;
12 01 12 34 76&lt;br&gt;
.... in decimal ....&lt;br&gt;
18 01 18 52 86&lt;br&gt;
18 01 18 52 102&lt;br&gt;
18 01 18 52 118&lt;br&gt;
.......&lt;br&gt;
&lt;br&gt;
I am currently &quot;decoding&quot; the BCD to its real decimal equivalent in the following way using bitshift and bitand.  Then converting to seconds of the day&lt;br&gt;
% T is time array (nx6) uint8&lt;br&gt;
h = bitshift(T(:,1),-4)*10 + bitand(15,T(:,1));&lt;br&gt;
m = bitshift(T(:,2),-4)*10 + bitand(15,T(:,2));&lt;br&gt;
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 ;&lt;br&gt;
TotalSec = h*3600+m*60+s;&lt;br&gt;
&lt;br&gt;
So my question is ...Is there an easier way to go from BCD to Decimal.</description>
    </item>
  </channel>
</rss>

