{"id":626,"date":"2013-08-03T15:45:56","date_gmt":"2013-08-03T15:45:56","guid":{"rendered":"http:\/\/blog.bachi.net\/?p=626"},"modified":"2013-08-03T15:46:16","modified_gmt":"2013-08-03T15:46:16","slug":"avr-binary-to-bcd-and-vice-versa","status":"publish","type":"post","link":"https:\/\/blog.bachi.net\/?p=626","title":{"rendered":"AVR: Binary to BCD and vice versa"},"content":{"rendered":"<pre class=\"brush: cpp; title: BCD to Binary; notranslate\" title=\"BCD to Binary\">\r\nunsigned int bcd2i(unsigned int bcd) {\r\n    unsigned int decimalMultiplier = 1;\r\n    unsigned int digit;\r\n    unsigned int i = 0;\r\n    while (bcd &gt; 0) {\r\n        digit = bcd &amp; 0xF;\r\n        i += digit * decimalMultiplier;\r\n        decimalMultiplier *= 10;\r\n        bcd &gt;&gt;= 4;\r\n    }\r\n    return i;\r\n}\r\n<\/pre>\n<pre class=\"brush: cpp; title: Binary to BCD; notranslate\" title=\"Binary to BCD\">\r\nunsigned int i2bcd(unsigned int i) {\r\n    unsigned int binaryShift = 0;\r\n    unsigned int digit;\r\n    unsigned int bcd = 0;\r\n    while (i &gt; 0) {\r\n        digit = i % 10;\r\n        bcd += (digit &lt;&lt; binaryShift);\r\n        binaryShift += 4;\r\n        i \/= 10;\r\n    }\r\n    return bcd;\r\n}\r\n<\/pre>\n<p><a href=\"http:\/\/www.expertcore.org\/viewtopic.php?f=8&#038;t=3742\">How to convert binary to BCD ?<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>unsigned int bcd2i(unsigned int bcd) { unsigned int decimalMultiplier = 1; unsigned int digit; unsigned int i = 0; while (bcd &gt; 0) { digit = bcd &amp; 0xF; i += digit * decimalMultiplier; decimalMultiplier *= 10; bcd &gt;&gt;= 4; } return i; } unsigned int i2bcd(unsigned int i) { unsigned int binaryShift = 0; [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[19],"tags":[],"class_list":["post-626","post","type-post","status-publish","format-standard","hentry","category-avr"],"_links":{"self":[{"href":"https:\/\/blog.bachi.net\/index.php?rest_route=\/wp\/v2\/posts\/626","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.bachi.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.bachi.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.bachi.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.bachi.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=626"}],"version-history":[{"count":2,"href":"https:\/\/blog.bachi.net\/index.php?rest_route=\/wp\/v2\/posts\/626\/revisions"}],"predecessor-version":[{"id":628,"href":"https:\/\/blog.bachi.net\/index.php?rest_route=\/wp\/v2\/posts\/626\/revisions\/628"}],"wp:attachment":[{"href":"https:\/\/blog.bachi.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=626"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.bachi.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=626"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.bachi.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=626"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}