Post by JohnG on Dec 23, 2011 7:49:56 GMT
bits, Bytes, binary and Hexadecimal
Before we can really start delving into some of the details of MIDI it helps if we have at least a basic understanding of bits, Bytes, binary and Hexadecimal. So let me try to deal with them in as simple a way as I know possible.
bits. Lets deal with the name first. It's an abbreviation of binary digits. What does binary mean? It means capable of representing two and only two things. So a binary star, for instance, is two stars that are very close together usually orbiting around each other. In computer terms it means something in the computer than can hold two values, either zero or one. In actual fact it's a single transistor that can be set to allow electricity to flow through it or not. So it's either on or off, just like a light. In fact it's probably most easy to think of it as just that, "a light," and you can switch it on and off, 1 or 0. In fact most modern electrical appliances have a symbol on their on/off switch which looks just like a 1 inside a 0. Go and have a look at your TV or hi-fi.
So a bit is a switch inside the computer (in its memory) that can be switched on (1) or off (0). Think of an electric light.
---------------------------------------------------------------------------------------------------------------
Bytes Again lets deal with the name. A Byte is a mouthful of bits. Yep, that's it, nothing more sinister! It happens to be agreed by most computer people today that a mouthful is always, exactly eight bits.
So a Byte is eight bits or, if you like, eight little switches (lights) which can be set to a large number of patterns of ons and offs. Like this: 0110 0101 or 0100 0000. in fact there are 256 different patterns between all off 0000 0000 and all on 1111 1111. Why the space in between the two sets of four bits? Well, it's often easier for humans to think of them this way. More of this when we look at hexadecimal.
---------------------------------------------------------------------------------------------------------------
Why do we need bits and Bytes? The bit is the basic building block from which all digital computers begin. But zeroes and ones by themselves don't actually allow us to do much with a computer. However, when we group them together in eights (a Byte) then we can start to hold meaningful (to us) information inside the computer by treating the patterns of 0s and 1s like a code. Like dots and dashes in Morse code.
Using Bytes to represent characters.
Just one example; if we think of text editing or, if you like, word processing, then we will want to represent, in the document, lots of different characters. 0 to 9, a to z, A to Z, "." (full stop or period), "," (comma), ?<>!$%&*- and so on, not to mention a variety of currency signs and accents from all over the world. If we sat down and made a list we'd probably come up with a list of at least a hundred. And I guess the computer needs a few special characters to indicate things like "new line", "new paragraph", "tab mark" and so on. So it's rather convenient that in a Byte we can set the bits to 256 different combinations. As long as we all agree what combination of bits represents which character then we can create a document and send it to anyone in the world and they'll be able to read it. Here's one 0010 0000 equals "space", really. There's a name for the most common code that we use and it's ASCII. Try Googling or Wikipedia it. Think of ASCII as the computer equivalent of Morse Code. You know "bip, bip, bip, beep, beep, bip, bip, bip" equals SMS. Or, better known, "bip, bip, bip, beep, beep, beep, bip, bip, bip" is SOS.
BTW ASCII stands for American Standard Code for Information Interchange.
Summary. So the bit is the basic building block of a digital computer. We group them together in eights so that they can hold something meaningful to us. We call eight bits a Byte. If we use a Byte to hold a character it's usually held using a code called ASCII.
Okay that's bits and Bytes.
------------------------------------------------------------------------------------------------------------------
What about binary
When we talk about using binary what we mean is that, instead of using a Byte to hold text data, we are going to use it (usually) to hold a number. In other words it may have something to do with arithmetic. But a computer doesn't have two sets of fingers and thumbs to work with, it just has bits, conveniently grouped into eights which we call Bytes. So how does it count? Well if I told you that the bits 0000 0000 = zero you would find that easy to understand. Then if I said 0000 0001 = one, likewise no problem. But if I then said 0000 0010 = two, you might have trouble. But in binary 1 + 1 = 10. No, not ten, we don't have ten in computer terms we just have ones and zeroes. Try this. For us 9 + 1 = 10. Try not to look at the answer but look at the process. There is no larger single digit than 9. So if we add 1 to 9 we have to create an extra column to hold the extra digit. A computer only has zeroes and ones so it has to create an extra column rather quickly and rather often..
---------------------------------------------------------------------------------------
Using Windoze calculator for binary, decimal and hexadecimal.
Try this. Open the Windows accessory "calculator". If you go to the "view" menu, at the top, you'll find you can change it to "scientific". Don't panic! All we're going to do is use the calculator to see how this works. The things we're interested in are the two indicators upper left "Dec" (decimal) and "Bin" (binary) and the normal numeric and arithmetic keys. We can swap between decimal (human) and binary (computer) views of the world, by mouse clicking in the appropriate button, or by using the keyboard keys "F6" and "F8". You'll find that you can, in decimal, type in a number and then convert to binary simply by the click of a button.
BTW the "Esc" key clears the display if you didn't already know.
Try entering "1" in decimal, convert to binary and add "1" (+ 1 =). Keep on adding "1" and you'll see a kind of pattern emerging. Swap back to decimal from time to time to check where you've got to.
BTW if you go to the "view" menu again you'll see "digit grouping". Select it and you'll notice that when you've added past 15 and shown it in binary you'll get little groups of four sets of numbers. Convenient eh! We call that half Byte a nibble (or nybble). It reminds me for some reason of Mr.Bean!
Okay. Hopefully by now you've got an idea of how binary works using bits and Bytes. Did you discover just how big a "number" we can hold in a Byte? Remember, eight bits, all ones. Go to the "Bin" view and type in a row of 8 ones. Click on "Dec" and we get 255. So all 0s to all 1s, 256 different combinations zero to 255.
That isn't very big is it? Clear the display and in decimal view type in 256 x 256 - 1 = the answer's 65,536 now go to binary view. Four blocks of four 1s. i.e. two bytes. Multiply by 256 again twice and subtract 1, answer 16 and 3/4 million (roughly) and so on. In other words the bigger the number we want to store the more Bytes we use. If we look just below the right side of the display (when we've selected hex, octal or binary) we'll see "Byte", "Word", "Dword" and "Qword". These are programmers ways of referring to Byte, 2 Bytes, 4 Bytes or 16 Bytes.
A quad Byte (no, not bike) can hold the following number 18,446,744,073,709,551,615. That should be big enough (just) to hold my pension in pennies (per month) in 4 years time. Ho, ho, I wish!
The MIDI channel number in binary and Hex
But what about MIDI? Okay clear the calculator screen and mess around with numbers between 0 and 15. You'll find that we never use more than half a Byte. i.e 0000 0000 to 0000 1111. (the top half of the Byte (nybble) remains zero.) That's how the MIDI channel number is stored. 16 binary values between 0 and 15. But we count from 1 to 16 don't we? No problem, when we want a MIDI channel number as the computer stores it we subtract one from the number (as we know it) and store it in binary. So channel 1 is binary 0, channel 16 is binary 1111 (15) so you'll see it represented as 00H to 0FH.
And we'll leave it there, for now anyway.
-----------------------------------------------------------------------------------
BUT there's got to be a more convenient way of displaying those 0s and 1s hasn't there?
Yup, and we call that Hexadecimal.
You'll find that converting from binary (F8 key) to hex (F5 key) using the calculator just gives a more simple display. It works like this. 0 to 9 decimal (0000 to 1001 binary) is also 0 to 9 hex. But 10 to 15 decimal (1010 to 1111 binary) are represented by hex "A" to "F". So we can convert a block of four bits into a hexadecimal character from 0 thru 9 thru A to F. So a Byte can be displayed like this 0FH meaning first nibble 0 (0000) second nibble F (1111) the H tells us we're looking at Hex.
End of lesson. Phew, tough!
Before we can really start delving into some of the details of MIDI it helps if we have at least a basic understanding of bits, Bytes, binary and Hexadecimal. So let me try to deal with them in as simple a way as I know possible.
bits. Lets deal with the name first. It's an abbreviation of binary digits. What does binary mean? It means capable of representing two and only two things. So a binary star, for instance, is two stars that are very close together usually orbiting around each other. In computer terms it means something in the computer than can hold two values, either zero or one. In actual fact it's a single transistor that can be set to allow electricity to flow through it or not. So it's either on or off, just like a light. In fact it's probably most easy to think of it as just that, "a light," and you can switch it on and off, 1 or 0. In fact most modern electrical appliances have a symbol on their on/off switch which looks just like a 1 inside a 0. Go and have a look at your TV or hi-fi.
So a bit is a switch inside the computer (in its memory) that can be switched on (1) or off (0). Think of an electric light.
---------------------------------------------------------------------------------------------------------------
Bytes Again lets deal with the name. A Byte is a mouthful of bits. Yep, that's it, nothing more sinister! It happens to be agreed by most computer people today that a mouthful is always, exactly eight bits.
So a Byte is eight bits or, if you like, eight little switches (lights) which can be set to a large number of patterns of ons and offs. Like this: 0110 0101 or 0100 0000. in fact there are 256 different patterns between all off 0000 0000 and all on 1111 1111. Why the space in between the two sets of four bits? Well, it's often easier for humans to think of them this way. More of this when we look at hexadecimal.
---------------------------------------------------------------------------------------------------------------
Why do we need bits and Bytes? The bit is the basic building block from which all digital computers begin. But zeroes and ones by themselves don't actually allow us to do much with a computer. However, when we group them together in eights (a Byte) then we can start to hold meaningful (to us) information inside the computer by treating the patterns of 0s and 1s like a code. Like dots and dashes in Morse code.
Using Bytes to represent characters.
Just one example; if we think of text editing or, if you like, word processing, then we will want to represent, in the document, lots of different characters. 0 to 9, a to z, A to Z, "." (full stop or period), "," (comma), ?<>!$%&*- and so on, not to mention a variety of currency signs and accents from all over the world. If we sat down and made a list we'd probably come up with a list of at least a hundred. And I guess the computer needs a few special characters to indicate things like "new line", "new paragraph", "tab mark" and so on. So it's rather convenient that in a Byte we can set the bits to 256 different combinations. As long as we all agree what combination of bits represents which character then we can create a document and send it to anyone in the world and they'll be able to read it. Here's one 0010 0000 equals "space", really. There's a name for the most common code that we use and it's ASCII. Try Googling or Wikipedia it. Think of ASCII as the computer equivalent of Morse Code. You know "bip, bip, bip, beep, beep, bip, bip, bip" equals SMS. Or, better known, "bip, bip, bip, beep, beep, beep, bip, bip, bip" is SOS.
BTW ASCII stands for American Standard Code for Information Interchange.
Summary. So the bit is the basic building block of a digital computer. We group them together in eights so that they can hold something meaningful to us. We call eight bits a Byte. If we use a Byte to hold a character it's usually held using a code called ASCII.
Okay that's bits and Bytes.
------------------------------------------------------------------------------------------------------------------
What about binary
When we talk about using binary what we mean is that, instead of using a Byte to hold text data, we are going to use it (usually) to hold a number. In other words it may have something to do with arithmetic. But a computer doesn't have two sets of fingers and thumbs to work with, it just has bits, conveniently grouped into eights which we call Bytes. So how does it count? Well if I told you that the bits 0000 0000 = zero you would find that easy to understand. Then if I said 0000 0001 = one, likewise no problem. But if I then said 0000 0010 = two, you might have trouble. But in binary 1 + 1 = 10. No, not ten, we don't have ten in computer terms we just have ones and zeroes. Try this. For us 9 + 1 = 10. Try not to look at the answer but look at the process. There is no larger single digit than 9. So if we add 1 to 9 we have to create an extra column to hold the extra digit. A computer only has zeroes and ones so it has to create an extra column rather quickly and rather often..
---------------------------------------------------------------------------------------
Using Windoze calculator for binary, decimal and hexadecimal.
Try this. Open the Windows accessory "calculator". If you go to the "view" menu, at the top, you'll find you can change it to "scientific". Don't panic! All we're going to do is use the calculator to see how this works. The things we're interested in are the two indicators upper left "Dec" (decimal) and "Bin" (binary) and the normal numeric and arithmetic keys. We can swap between decimal (human) and binary (computer) views of the world, by mouse clicking in the appropriate button, or by using the keyboard keys "F6" and "F8". You'll find that you can, in decimal, type in a number and then convert to binary simply by the click of a button.
BTW the "Esc" key clears the display if you didn't already know.
Try entering "1" in decimal, convert to binary and add "1" (+ 1 =). Keep on adding "1" and you'll see a kind of pattern emerging. Swap back to decimal from time to time to check where you've got to.
BTW if you go to the "view" menu again you'll see "digit grouping". Select it and you'll notice that when you've added past 15 and shown it in binary you'll get little groups of four sets of numbers. Convenient eh! We call that half Byte a nibble (or nybble). It reminds me for some reason of Mr.Bean!
Okay. Hopefully by now you've got an idea of how binary works using bits and Bytes. Did you discover just how big a "number" we can hold in a Byte? Remember, eight bits, all ones. Go to the "Bin" view and type in a row of 8 ones. Click on "Dec" and we get 255. So all 0s to all 1s, 256 different combinations zero to 255.
That isn't very big is it? Clear the display and in decimal view type in 256 x 256 - 1 = the answer's 65,536 now go to binary view. Four blocks of four 1s. i.e. two bytes. Multiply by 256 again twice and subtract 1, answer 16 and 3/4 million (roughly) and so on. In other words the bigger the number we want to store the more Bytes we use. If we look just below the right side of the display (when we've selected hex, octal or binary) we'll see "Byte", "Word", "Dword" and "Qword". These are programmers ways of referring to Byte, 2 Bytes, 4 Bytes or 16 Bytes.
A quad Byte (no, not bike) can hold the following number 18,446,744,073,709,551,615. That should be big enough (just) to hold my pension in pennies (per month) in 4 years time. Ho, ho, I wish!
The MIDI channel number in binary and Hex
But what about MIDI? Okay clear the calculator screen and mess around with numbers between 0 and 15. You'll find that we never use more than half a Byte. i.e 0000 0000 to 0000 1111. (the top half of the Byte (nybble) remains zero.) That's how the MIDI channel number is stored. 16 binary values between 0 and 15. But we count from 1 to 16 don't we? No problem, when we want a MIDI channel number as the computer stores it we subtract one from the number (as we know it) and store it in binary. So channel 1 is binary 0, channel 16 is binary 1111 (15) so you'll see it represented as 00H to 0FH.
And we'll leave it there, for now anyway.
-----------------------------------------------------------------------------------
BUT there's got to be a more convenient way of displaying those 0s and 1s hasn't there?
Yup, and we call that Hexadecimal.
You'll find that converting from binary (F8 key) to hex (F5 key) using the calculator just gives a more simple display. It works like this. 0 to 9 decimal (0000 to 1001 binary) is also 0 to 9 hex. But 10 to 15 decimal (1010 to 1111 binary) are represented by hex "A" to "F". So we can convert a block of four bits into a hexadecimal character from 0 thru 9 thru A to F. So a Byte can be displayed like this 0FH meaning first nibble 0 (0000) second nibble F (1111) the H tells us we're looking at Hex.
End of lesson. Phew, tough!