{"id":9,"date":"2015-07-16T00:51:21","date_gmt":"2015-07-16T00:51:21","guid":{"rendered":"http:\/\/rageworx.iptime.org\/?p=9"},"modified":"2025-01-13T14:35:10","modified_gmt":"2025-01-13T05:35:10","slug":"printing-bits-from-unsigned-char-byte-in-c","status":"publish","type":"post","link":"https:\/\/rageworx.info\/?p=9","title":{"rendered":"Printing bits from unsigned char (BYTE) in C."},"content":{"rendered":"<p>Anybody knows what numbers made in our computer if you have experience in programming. But have you tried to print what &#8216;unsigned char&#8217; or &#8216;BYTE&#8217;, 1 byte data to bits?FF<br \/>\n&#8216;unsigned char&#8217; and &#8216;BYTE&#8217; contain a number in ranged 0 to 255 in 8 bits. 0000:0000 to 1111:1111. All numbers made in bits, a digital switched. So I made this expression for simple C code.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"c\">const char* uchar2bits( unsigned char uc ) \r\n{\r\n\u00a0\u00a0\u00a0 static char outstr_uc[10];\r\n    int cnt;\r\n    unsigned char dec;\r\n    int que = 0;\u00a0\u00a0 \r\n    \r\n    memset( outstr_uc, 0, 10 ); \u00a0\u00a0\u00a0 \r\n    outstr_uc[4] = ':'; \u00a0\u00a0\u00a0 \r\n    \r\n    for ( cnt = 7 ; cnt &gt;= 0 ; cnt-- )\r\n    {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 dec = uc &gt;&gt; cnt;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 if ( dec &amp; 1 ) outstr_uc[que] = 1 + '0';\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 else \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 outstr_uc[que] = 0 + '0';\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 que++;\r\n\r\n        if ( que == 4 ) que++;\r\n    } \r\n    return outstr_uc; \r\n}<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Anybody knows what numbers made in our computer if you have experience in programming. But have you tried to print what &#8216;unsigned char&#8217; or &#8216;BYTE&#8217;, 1 byte data to bits?FF &#8216;unsigned char&#8217; and &#8216;BYTE&#8217; contain a number in ranged 0 to 255 in 8 bits. 0000:0000 to 1111:1111. All numbers&#8230; <a href=\"https:\/\/rageworx.info\/?p=9\">Read more &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,3],"tags":[10,11],"class_list":["post-9","post","type-post","status-publish","format-standard","hentry","category-development","category-raphs","tag-c","tag-code"],"_links":{"self":[{"href":"https:\/\/rageworx.info\/index.php?rest_route=\/wp\/v2\/posts\/9","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/rageworx.info\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/rageworx.info\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/rageworx.info\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/rageworx.info\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=9"}],"version-history":[{"count":3,"href":"https:\/\/rageworx.info\/index.php?rest_route=\/wp\/v2\/posts\/9\/revisions"}],"predecessor-version":[{"id":2726,"href":"https:\/\/rageworx.info\/index.php?rest_route=\/wp\/v2\/posts\/9\/revisions\/2726"}],"wp:attachment":[{"href":"https:\/\/rageworx.info\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=9"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/rageworx.info\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=9"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/rageworx.info\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=9"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}