{"id":4197,"date":"2014-12-31T10:23:06","date_gmt":"2014-12-31T18:23:06","guid":{"rendered":"https:\/\/blog.digilentinc.com\/?p=4197"},"modified":"2025-06-03T06:44:20","modified_gmt":"2025-06-03T13:44:20","slug":"true-or-false-boolean-is-a-data-type","status":"publish","type":"post","link":"https:\/\/digilent.com\/blog\/true-or-false-boolean-is-a-data-type\/","title":{"rendered":"Is Boolean a Data Type?"},"content":{"rendered":"<p>Welcome back to the Digilent Blog!<\/p>\n<p>True! Boolean is a data type. However, it&#8217;s also a term that gets thrown around in the electronics world by programmers presuming that everybody else knows what they are talking about; I can personally attest that this is not always the case. In light of this, let&#8217;s go over some of the data types that are commonly used in programming.<\/p>\n<p>But first things first, what is a data type? In a broad sense, data types are ways to represent different kinds of information in a computer processor or FPGA. Today we will be discussing booleans, integers, chars, and floating point numbers, all of which are commonly known as primitive data types. There are also other types of data, known as composite data types, although these are generally just combinations of the primitive data types, such as an <a title=\"Arrays \u2014 They\u2019re Not So Scary\" href=\"https:\/\/digilent.com\/blog\/index.php\/arrays-theyre-not-so-scary\/\" target=\"_blank\" rel=\"noopener\">array<\/a>. Computer processors, microprocessors, and FPGAs all store these data types in a binary format as a series of 1&#8217;s and 0&#8217;s. Within the computer system each &#8216;1&#8217; or &#8216;0&#8217; (a bit) is classically grouped together in sets of eight to form what is known as a byte. Because a processor will communicate in this byte format, every data type, even if it only needs one bit to be represented, will be stored inside of a byte.<\/p>\n<figure id=\"attachment_4242\" aria-describedby=\"caption-attachment-4242\" style=\"width: 601px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/digilent.com\/blog\/wp-content\/uploads\/2014\/12\/32-bits-into-4-bytes.png\"><img loading=\"lazy\" decoding=\"async\" class=\" wp-image-4242\" src=\"https:\/\/digilent.com\/blog\/wp-content\/uploads\/2014\/12\/32-bits-into-4-bytes.png\" alt=\"32 bits of data will be sectioned off into four bytes with eight bits each.\" width=\"601\" height=\"96\" srcset=\"https:\/\/digilent.com\/blog\/wp-content\/uploads\/2014\/12\/32-bits-into-4-bytes.png 1228w, https:\/\/digilent.com\/blog\/wp-content\/uploads\/2014\/12\/32-bits-into-4-bytes-600x96.png 600w, https:\/\/digilent.com\/blog\/wp-content\/uploads\/2014\/12\/32-bits-into-4-bytes-1024x163.png 1024w, https:\/\/digilent.com\/blog\/wp-content\/uploads\/2014\/12\/32-bits-into-4-bytes-225x36.png 225w\" sizes=\"auto, (max-width: 601px) 100vw, 601px\" \/><\/a><figcaption id=\"caption-attachment-4242\" class=\"wp-caption-text\">32 bits of data will be sectioned off into four bytes with eight bits each.<\/figcaption><\/figure>\n<p>A boolean, as you might have guessed, is a data type that represents &#8220;true&#8221; or &#8220;false&#8221;. However, when storing information on a computer, there is no hardware that is capable of storing a literal &#8220;true or false&#8221;, so many programming languages will instead have the true and false values be equivalent to the numbers &#8216;1&#8217; and &#8216;0&#8217; represented by high and low voltages. This allows for the potential operation of &#8220;true +\u00a0true&#8221; being equal to &#8216;2&#8217;. How this fun fact is actually useful in a real life situation is beyond me, but hey, fun facts are still fun! The true or false nature of a boolean makes it a great way to keep track of something that is triggered &#8220;on or off&#8221; or &#8220;left and right&#8221;.<\/p>\n<figure style=\"width: 300px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"\" src=\"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2012\/04\/TrueFalse-300x200.png\" alt=\"\" width=\"300\" height=\"200\" \/><figcaption class=\"wp-caption-text\">The two options for a Boolean data type. Image from <a href=\"http:\/\/jdhitsolutions.com\/blog\/scripting\/2231\/convert-boolean-values\/\" target=\"_blank\" rel=\"noopener\">jdhitsolutions.com<\/a>.<\/figcaption><\/figure>\n<p>A character, commonly called a char, is an array of bits (one byte worth in C++) that define a visual representation of a symbol. These symbols are commonly defined by the <a title=\"ASCII Table\" href=\"http:\/\/www.asciitable.com\/\" target=\"_blank\" rel=\"noopener\">ASCII table<\/a>\u00a0and consist of many of the characters that you see on your keyboard. Characters are technically a composite data type as many characters can be placed together to form a string (a series of characters) as well as the fact that an array of bits (representing pixels that can be turned on or off) are needed to display each of the characters. With the right resources, you can also <a title=\"Creating Custom Characters on the PmodOLED\" href=\"https:\/\/digilent.com\/blog\/index.php\/creating-custom-characters-on-the-pmodoled\/\">define your own set of characters<\/a> to display &#8220;non-standard&#8221; characters.<\/p>\n<p>&nbsp;<\/p>\n<figure id=\"attachment_3409\" aria-describedby=\"caption-attachment-3409\" style=\"width: 600px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/digilent.com\/blog\/wp-content\/uploads\/2014\/11\/Two-defined-characters-photo.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\" wp-image-3409\" src=\"https:\/\/digilent.com\/blog\/wp-content\/uploads\/2014\/11\/Two-defined-characters-photo.jpg\" alt=\"The PmodOLED displaying our two defined characters.\" width=\"600\" height=\"450\" srcset=\"https:\/\/digilent.com\/blog\/wp-content\/uploads\/2014\/11\/Two-defined-characters-photo.jpg 3501w, https:\/\/digilent.com\/blog\/wp-content\/uploads\/2014\/11\/Two-defined-characters-photo-600x449.jpg 600w, https:\/\/digilent.com\/blog\/wp-content\/uploads\/2014\/11\/Two-defined-characters-photo-1024x767.jpg 1024w, https:\/\/digilent.com\/blog\/wp-content\/uploads\/2014\/11\/Two-defined-characters-photo-225x168.jpg 225w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/a><figcaption id=\"caption-attachment-3409\" class=\"wp-caption-text\">The PmodOLED displaying a variety of\u00a0characters.<\/figcaption><\/figure>\n<p>Integers, usually shortened to just int, are the standard way to store numbers within your code. They are able to store a variety of numbers including binary, decimal, and hexadecimal numbers and do not require any special manipulation process on the programmer&#8217;s part to store one number type over a different one inside of an int. On chipKIT\u2122 boards with their PIC32 processor, integers are 32 bits long allowing them to store numbers ranging from -2,147,483,647 to +2,147,483,647 for the signed (positive or negative) and from 0 to 4,294,967,295 for the unsigned (just positive) version. Despite being natively 32 bits long, it is possible to declare an integer that is of a smaller value such as only 16 bits or 8 bits in order to conserve space within the processor, although naturally this will be done at the expense of an exponentially shortened number size that those integers can accept. The restriction with integers is that they are unable to accept any decimal places. If you attempted to give an integer a value of 31.96, it will only store the 31. The 0.96 will instead be truncated, meaning that it will be discarded entirely with no rounding whatsoever.<\/p>\n<p>&nbsp;<\/p>\n<figure id=\"attachment_4200\" aria-describedby=\"caption-attachment-4200\" style=\"width: 599px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/digilent.com\/blog\/wp-content\/uploads\/2014\/12\/truncation-of-an-int.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-4200\" src=\"https:\/\/digilent.com\/blog\/wp-content\/uploads\/2014\/12\/truncation-of-an-int.jpg\" alt=\"The inherent nature of an integer\" width=\"599\" height=\"167\" srcset=\"https:\/\/digilent.com\/blog\/wp-content\/uploads\/2014\/12\/truncation-of-an-int.jpg 700w, https:\/\/digilent.com\/blog\/wp-content\/uploads\/2014\/12\/truncation-of-an-int-600x167.jpg 600w, https:\/\/digilent.com\/blog\/wp-content\/uploads\/2014\/12\/truncation-of-an-int-225x63.jpg 225w\" sizes=\"auto, (max-width: 599px) 100vw, 599px\" \/><\/a><figcaption id=\"caption-attachment-4200\" class=\"wp-caption-text\">The inherent nature of an integer.<\/figcaption><\/figure>\n<p>&nbsp;<\/p>\n<p>The final data type that I will talk about is a floating point. This is a data type that is able to accept numbers with decimal places. The way that this data type works is through a style of scientific notation; a given number is arranged so that there is one value before the decimal point and the rest of the significant numbers are after the decimal point with eight bits out of the 32 dedicated towards the exponent indicating the magnitude of the number.<\/p>\n<p>&nbsp;<\/p>\n<figure style=\"width: 590px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"\" src=\"https:\/\/upload.wikimedia.org\/wikipedia\/commons\/thumb\/d\/d2\/Float_example.svg\/590px-Float_example.svg.png\" alt=\"\" width=\"590\" height=\"75\" \/><figcaption class=\"wp-caption-text\">A breakdown of a 32-bit float. Image by Fresheneesz from this <a href=\"https:\/\/en.wikipedia.org\/wiki\/Single-precision_floating-point_format\" target=\"_blank\" rel=\"noopener\">Wikipedia page<\/a>.<\/figcaption><\/figure>\n<p>In terms of real life application, this equates to a &#8220;float&#8221; being able to handle and keep track of about seven decimal points. A &#8220;double&#8221; is similar to a float, except that it uses two sets of 32 bits for a total of 64 bits (eight bytes). As a double-precision floating value (hence the name), it is able to keep track of about 16 decimal places, allowing for more accurate calculations, although calculations involving doubles do take longer than floats because they take up two slots of memory in a PIC32. Luckily, when running at 80 MHz on Digilent&#8217;s chipKIT boards, this time difference is negligible for most applications.<\/p>\n<p>&nbsp;<\/p>\n<div class='watch-action'><div class='watch-position align-left'><div class='action-like'><a class='lbg-style6 like-4197 jlk' data-task='like' data-post_id='4197' data-nonce='1cb2a57891' rel='nofollow'><img src='https:\/\/digilent.com\/blog\/wp-content\/plugins\/wti-like-post-pro\/images\/pixel.gif' title='Like' \/><span class='lc-4197 lc'>+1<\/span><\/a><\/div><div class='action-unlike'><a class='unlbg-style6 unlike-4197 jlk' data-task='unlike' data-post_id='4197' data-nonce='1cb2a57891' rel='nofollow'><img src='https:\/\/digilent.com\/blog\/wp-content\/plugins\/wti-like-post-pro\/images\/pixel.gif' title='Unlike' \/><span class='unlc-4197 unlc'>0<\/span><\/a><\/div><\/div> <div class='status-4197 status align-left'><\/div><\/div><div class='wti-clear'><\/div>","protected":false},"excerpt":{"rendered":"<p>True! Boolean is a data type. However, it&#8217;s also a term that gets thrown around in the electronics world by programmers presuming that everybody else knows what they are talking about; I can personally attest that this is not always the case. In light of this, let&#8217;s go over some of the data types that are commonly used in programming.<\/p>\n","protected":false},"author":17,"featured_media":4243,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[1563],"tags":[],"ppma_author":[4469],"class_list":["post-4197","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-guide"],"jetpack_featured_media_url":"https:\/\/digilent.com\/blog\/wp-content\/uploads\/2014\/12\/boolean-true-false.png","authors":[{"term_id":4469,"user_id":17,"is_guest":0,"slug":"jamescolvin","display_name":"James Colvin","avatar_url":"https:\/\/secure.gravatar.com\/avatar\/8aa85f7d11711acc7e571e1ed26c901b614a7064a2e15e522f54d9f26792ea9e?s=96&d=mm&r=g","1":"","2":"","3":"","4":"","5":"","6":"","7":"","8":"","9":"","10":""}],"post_mailing_queue_ids":[],"_links":{"self":[{"href":"https:\/\/digilent.com\/blog\/wp-json\/wp\/v2\/posts\/4197","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/digilent.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/digilent.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/digilent.com\/blog\/wp-json\/wp\/v2\/users\/17"}],"replies":[{"embeddable":true,"href":"https:\/\/digilent.com\/blog\/wp-json\/wp\/v2\/comments?post=4197"}],"version-history":[{"count":2,"href":"https:\/\/digilent.com\/blog\/wp-json\/wp\/v2\/posts\/4197\/revisions"}],"predecessor-version":[{"id":31625,"href":"https:\/\/digilent.com\/blog\/wp-json\/wp\/v2\/posts\/4197\/revisions\/31625"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/digilent.com\/blog\/wp-json\/wp\/v2\/media\/4243"}],"wp:attachment":[{"href":"https:\/\/digilent.com\/blog\/wp-json\/wp\/v2\/media?parent=4197"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/digilent.com\/blog\/wp-json\/wp\/v2\/categories?post=4197"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/digilent.com\/blog\/wp-json\/wp\/v2\/tags?post=4197"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/digilent.com\/blog\/wp-json\/wp\/v2\/ppma_author?post=4197"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}