Bits and Binary 101 = 5


It's not necessary to understand binary code to work with digital audio but it is useful when learning the theories behind digital sampling. Every time you start a new session in your DAW or bounce your finished production out to the rest of the world you make decisions concerning sample rates, bit depth or bit rates. You probably already know that the settings you choose for these parameters effect the quality of your audio. Having a basic grasp of what those ones and zeros mean in these contexts can help you make more informed decisions. So here we go...


Decimal (base-10) numbers

We learn to count using a decimal or base-10 system. This becomes so second-nature and intuitive to us that we're barely cognizant of it. In our decimal number system we have
  • nine different digits representing the values zero through nine (0-9) 
  • no single digit for the number ten (10) or greater 
so
  • each time we exceed a value of 9 we add a new number column to the left of that digit and start over again with 1 
  • each new column represents a value ten times the column to its right 
For example, we immediately recognize the value of the number "101" without having to think that it represents 1 hundred, 0 tens and 1 one. If we were trying to explain this concept to someone who had never been exposed to it before it might help to present the number in a table:
In a decimal number system each column represents a value 10 times greater than the column to its right

Binary (base-2) numbers

A binary or base-2 system uses
  • two digits representing the values zero through one (0-1)
  • when we exceed the value of 1 we start over again with a new column on the left
  • each new column represents a value two times the column to its right

In a binary number system each column represents a value 2 times greater than the column to its right
binary-switch-off-on
As an analogy for reading binary code it's often said that you can think of its zeroes and ones as switches; zero being "off" and one being "on". I like this analogy because we also tend to think of a switch as a device that controls a circuit or a machine. And right now you're reading this post on a machine that's using a lot of electronic switches. 

Let's plug our "101" into a binary table and see what we get. Keep in mind that it no longer represents the decimal value "one hundred and one". Instead think of it as a series of on and off switches.

Reading the table above from right to left:
  • the "one" column is switched on returning a decimal value of 1
  • the "two" column is switched off returning a decimal value of 0
  • the "four" column is switched on returning a decimal value of 4  
  • add the values together and you get decimal 5
Get it? If you're still unsure study the table below and it should start to make sense. Remember to look at the binary ones and zeros as switches; they just turn the value at the top of their column on or off.
binary-table

Bits

In geek speak a bit is a contraction of the words binary digit. Every single zero or one in a string of binary numbers constitutes one bit. 

The table above illustrates every possible 3-bit binary number with its decimal equivalent presented on the right. Take a look and note that:
  • using only one bit there are 2 possible values: 0 and 1. To express a value larger than 1 it's necessary to add another bit to the left.
  • using two bits there are 4 possible values: 00, 01, 10 and 11. To express a value larger than 11 it's necessary to add another bit to the left.
  • with three bits there are 8 possible values: 000, 001, 010, 011, 100, 101, 110 and 111. To express a value larger than 111 it's necessary to add another bit to the left.
Note: if you just read 111 as "one hundred eleven" please go stare at the picture of the light switches above

Do you see any patterns here?
  • for every single bit added to a binary word the range of possible values doubles. If you didn't notice look at the table again. Understanding this is going to be very helpful when you learn about bit depth, quantization and dynamic range in digital audio systems.
  • when every bit in a binary word is at "1" it has reached its maximum value and can't increase any further. In digital audio these maximum values are referred to as full scale and trying to exceed them will result in clipping. Heard of that?

Bytes

01000010

A string of eight bits together is called a byte and represented by an uppercase "B".  We most often run across bytes in our day to day work when referencing file size or storage space.

Conversely, bits are represented by a lowercase "b" and commonly used to indicate bit rate which refers to the amount of data transferred or processed in one second.  

File size and bit rate are different terms which are often confused. Remember to look for the big "B" for bytes or little "b" for bits. Now you know...
On the left the storage requirements of a Pro Tools session folder is shown in GigaBytes.
On the right the bit rate of a mp3 file is shown in kilobits per second.


Machine Code


Finally, if you want to have a few bits (or bytes) of fun click on this link and type in your name or favorite ice cream flavor. In return you'll get to see what the processor on your device is really looking at once your entry gets through your browser, your OS and many, many layers of programming languages.


Something to keep in mind as you look at all those 1s and 0s: the processor on your device doesn't see them as we do. A "1" to your processor is just a little voltage—a little bit of electricity. A "0" means no voltage. 

Every single bit is processed by your device on a tiny transistor: an electronic switch that's either on or off. 

Amazing.




Next time we're going to put your new binary knowledge to good use as we begin to cover the analog to digital audio conversion process in detail.



This book was my primary reference for this article. A great read for those who are interested in learning how your digital devices really work under the hood.






Karl Wenninger is an audio engineer, synthesist/sound designer, composer, guitarist and DIY audio electronics enthusiast. As an adjunct professor he has taught
 Pro Tools at The New School for Jazz and Contemporary Music, Computer Music at York College and Audio Post-Production for the Media Arts Program at NJCUHe was an program administrator and associate professor at the former Digital Media Arts program at Touro College in New York City for over a decade. 

No comments:

Post a Comment