{"id":559,"date":"2012-04-12T18:57:12","date_gmt":"2012-04-12T18:57:12","guid":{"rendered":"http:\/\/www.sitekickr.com\/blog\/?p=559"},"modified":"2012-04-14T11:34:22","modified_gmt":"2012-04-14T11:34:22","slug":"dont-forget-base-2","status":"publish","type":"post","link":"https:\/\/www.sitekickr.com\/blog\/dont-forget-base-2\/","title":{"rendered":"Don&#8217;t forget about Base 2"},"content":{"rendered":"<p>We&#39;ve all gotten so used to high-level programming that we often forget about how compact and clean machine code really is. Wait a minute, let&#39;s not go there. Machine code may be efficient but who wants to go back to using 1&#39;s and 0&#39;s in their rapid application development?<\/p>\n<p>We usually can&#39;t use rapid development and efficient code in the same sentence, but there are some areas where the two play nicely together, namely in data storage.<\/p>\n<p>Consider that you have a database table which stores your customer&#39;s preferences. One such column is used to store the days of the week that they prefer to be emailed about daily specials.<\/p>\n<p>You could create a cross-reference table to store the days of the week, you could create a simple varchar(8) field to store the day numbers or letters. Or, you could revisit those 1&#39;s and 0&#39;s again.<\/p>\n<p>What if each day of the week was represented by one bit in an 8-bit TINYINT field? Or, if you have a newer version of MySQL, the <a href=\"http:\/\/dev.mysql.com\/doc\/refman\/5.0\/en\/bit-field-literals.html\">bit data type<\/a> would be more appropriate.<\/p>\n<p>1001001 would mean: Sunday, Wednesday, Saturday<\/p>\n<p>In base 10, this number is 73, and fits nicely inside a single-byte TINYINT field, as suggested above.<\/p>\n<p>Just about every coding language out there provides functions to convert between Base 2 and Base 10. So, consider this approach when you have a large number of records, and storage space is at a premium.<\/p>\n<p>See the <a href=\"\/coda\/sql\/determine-bit.html\">Determine if a bit is on or off<\/a> coda post if you are not using the MySQL bit field.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>We&#39;ve all gotten so used to high-level programming that we often forget about how compact and clean machine code really is. Wait a minute, let&#39;s&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"amp_status":""},"categories":[15,13],"tags":[166],"_links":{"self":[{"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/posts\/559"}],"collection":[{"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/comments?post=559"}],"version-history":[{"count":4,"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/posts\/559\/revisions"}],"predecessor-version":[{"id":563,"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/posts\/559\/revisions\/563"}],"wp:attachment":[{"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/media?parent=559"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/categories?post=559"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/tags?post=559"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}