{"id":250,"date":"2010-03-16T10:11:02","date_gmt":"2010-03-16T15:11:02","guid":{"rendered":"http:\/\/www.buluschek.com\/?p=250"},"modified":"2023-07-02T10:49:23","modified_gmt":"2023-07-02T08:49:23","slug":"convert-byte-to-binary-representation","status":"publish","type":"post","link":"https:\/\/www.buluschek.com\/?p=250","title":{"rendered":"Convert byte to binary representation"},"content":{"rendered":"<p>Use the following to show a byte value in binary representation.<br \/>\n[sourcecode lang=&#8221;java&#8221;]<br \/>\n\/**<br \/>\n * Returns a 0 padded binary representation of the<br \/>\n * passed byte. For example, returns &quot;00000001&quot; if passed<br \/>\n * the byte 1. Returns &quot;11111111&quot; if passed byte -1.<br \/>\n * @param b the byte<br \/>\n * @return the byte in binary representation<br \/>\n *\/<br \/>\nprivate static String toBinary(byte b){<br \/>\n\tStringBuffer sb = new StringBuffer(8);<br \/>\n\tfor(int bit = 7; bit &gt;= 0; bit&#8211;) {<br \/>\n\t\tif ((b &amp; (1 &lt;&lt; bit)) &gt; 0)<br \/>\n\t\t\tsb.append(&#8216;1&#8217;);<br \/>\n\t\telse<br \/>\n\t\t\tsb.append(&#8216;0&#8217;);<br \/>\n\t}<br \/>\n\treturn sb.toString();<br \/>\n}<br \/>\n[\/sourcecode]<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Use the following to show a byte value in binary representation. [sourcecode lang=&#8221;java&#8221;] \/** * Returns a 0 padded binary representation of the * passed byte. For example, returns &quot;00000001&quot; if passed * the byte 1. Returns &quot;11111111&quot; if passed byte -1. * @param b the byte * @return the byte in binary representation *\/ [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[27],"class_list":["post-250","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-java"],"_links":{"self":[{"href":"https:\/\/www.buluschek.com\/index.php?rest_route=\/wp\/v2\/posts\/250","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.buluschek.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.buluschek.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.buluschek.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.buluschek.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=250"}],"version-history":[{"count":8,"href":"https:\/\/www.buluschek.com\/index.php?rest_route=\/wp\/v2\/posts\/250\/revisions"}],"predecessor-version":[{"id":338,"href":"https:\/\/www.buluschek.com\/index.php?rest_route=\/wp\/v2\/posts\/250\/revisions\/338"}],"wp:attachment":[{"href":"https:\/\/www.buluschek.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=250"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.buluschek.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=250"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.buluschek.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=250"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}