Our VIP Package gets you every single course at 80% off the individual price. For a limited time, save an additional $100 with coupon code 100VIP. Learn more

CAN Bus Communications Decoded: Binary, Decimal and Hex

Watch This Course

$199.00 USD $129.00 USD

-OR-
Or 8 weekly payments of only $16.13 Instant access. Easy checkout. No fees. Learn more
Course Access for Life
60 day money back guarantee

Binary, Decimal and Hex

07.54

00:00 - Before we dive right into the deep end, in order to thoroughly understand the implementation and usage of CAN communications in our vehicles, we're going to need to first cover some general technical background theory about how electronic devices more generally work and communicate with one another.
00:15 While we will be talking about terms like bits, bytes, binary, decimal and hexadecimal, don't be intimidated or let these turn you off.
00:24 I promise these concepts are relatively simple once they've been explained and being confident with them is going to really help using CAN communications in your project.
00:33 We'll start with the terms binary, decimal and hexadecimal.
00:37 These terms refer to numerical systems with different bases.
00:41 The base of a numerical system is simply the number of different symbols that a system has to indicate different numbers.
00:48 To start with, let's have a look at the decimal system as this is the one that we are all familiar with and use in our daily lives.
00:54 Using the decimal system, is likely second nature and you don't give any thought to how it works but we'll break it down a little with a couple of simple examples and then show how these examples differ when we use binary or hexadecimal.
01:07 The decimal system uses a base of 10, this means there are 10 different symbols available to describe numbers.
01:14 These being the digits 0-9.
01:18 To show how we use these symbols, let's say we want to count the number of cylinders in an engine.
01:23 If we're looking at an LS1 engine for example and we want to write down how many cylinders this engine has, we can use a single symbol for this which is the digit 8.
01:33 We can use a single symbol because the number we want to describe is less than the base of our numerical system.
01:40 But if we then go and stand behind a Lamborghini Diablo and want to describe the number of cylinders in that engine which is 12, this is higher than the base of our decimal system and we don't have an individual symbol available to describe this number.
01:54 This means we need to use a combination of our available symbols which in this case will be a 1 followed by a 2.
02:01 When we write this down, what we're really saying is that the number we're describing is 1 times our system base of 10 plus 2 times 1 or 10 plus 2 which is 12.
02:12 If we then wanted to describe the number of cylinders in both engines together, we would write down a 2 followed by a 0, meaning 2 times our system base of 10, plus 0 times 1 which is 20.
02:24 Let's try the same examples again but using the hexadecimal system this time which has a base of 16.
02:31 This means we now have 16 available symbols to describe numbers, being the digits 0-9, followed by the letters A-F, representing the numbers 10 to 15 respectively.
02:41 To describe the number of cylinders in our LS1 engine, this is still lower than our numerical system base so we can still use a single symbol to describe this number.
02:50 Once again, this is the digit 8.
02:53 Back at the Lamborghini however, our numerical system base of 16 is now higher than the number that we want to describe so we have a single symbol available to us that represents the number 12 which is C.
03:04 However describing the total number of cylinders in both engines is once again a higher number than our numerical base of 16 so we'll again need to use a combination of symbols.
03:15 In this case we'd write down the digit 1, followed by the digit 4.
03:19 In the hexadecimal system, this means 1 times our system base of 16, plus 4 times 1 or 16 plus 4 which is 20.
03:29 This is where a lot of the confusion can come in as when we see the symbols 1 and 4 put next to one another, we immediately think of the number 14 because we're so used to the decimal system.
03:40 To help with this, when we write down a number in hexadecimal, we prefix it with 0x so to write down the number 20 in hexadecimal, we would write down 0x14.
03:51 Back to our cylinder counting examples, we'll look at how they would differ if we were working in binary.
03:57 Binary has a base of 2, meaning we only have 2 different symbols available to us to describe different numbers, being the digits 0 and 1.
04:05 Straight away, the number of cylinders in our LS1 engine is higher than our numerical system base so we're going to need to use a combination of our available symbols.
04:13 In this case, we would write down the digit 1 followed by 3 zeros.
04:18 It's important to understand that every column our number has is the number of times the symbol in that column is multiplied by the system base before everything gets added together to get the overall number that we're representing.
04:32 This sounds complicated but you'll probably remember learning this in school for the decimal system as the 1s column, 10s column, 100s colum and so on.
04:41 If we write down 138 in decimal, this means 1 times 10 twice, so that's 1 times 100, plus 3 times 10, 30, plus 8 or 138.
04:53 This is the same for our binary example except our base is 2.
04:57 So 1000 means 1 times 2, 3 times which is 1 times 8, plus 0 times 2 twice, plus 0 times 2 plus 0 which is 8 plus 3 zeros or just 8.
05:15 For our Lamborghini example with 12 cylinders, we would write this down as 1100 meaning 1 times 2, 3 times, 8, plus 1 times 2 twice which is 4, plus 0, plus 0 which gives us 12 all up.
05:30 Once again if we just saw 1100 written down, we would instinctively read this as one thousand one hundred because we're so used to the decimal system.
05:39 So to make it clear we're writing down a number in binary, we prefix it with 0b.
05:45 So we would write down 0b1100.
05:49 To describe the total number of cylinders in both engines, we would write down 0b10100 meaning 1 times 2, 4 times, which is 16, plus 0, plus 1 times 2, 2 times which is 4, plus 0 plus 0, or 16 plus 4 which is 20.
06:09 Until you get some experience reading and interpreting binary and hexadecimal, they can seem a little bit daunting.
06:14 But luckily there is a very common tool to allow you to translate between these numerical bases easily and that is the Windows calculator application.
06:23 If you load the calculator application and change the mode to programmer, you can choose to enter a number in binary, decimal or hexadecimal and see how it would be described in the other numerical systems.
06:34 Trying this now, if we put the calculator into programmer mode, and the numerical system set to hexadecimal, then enter 14, you can see this is 20 in decimal and 10100 in binary.
06:49 All these representations mean exactly the same thing which is the number 20.
06:54 They're just being shown in different numerical base systems.
06:58 If you're more familiar working in Linux or Mac OS there are likely similar applications available there or a quick Google will find you an online version.
07:05 In the real world, the reason we need to know about binary, decimal and hexadecimal is that different electronics manufacturers use the different systems and we need to be able to convert from one to the other to make sure everything will communicate reliably.
07:18 It is unlikely you'll be doing any complicated math in binary or hex so a complete understanding of them is not crucial but you do need to know that they exist and how to convert between them.
07:29 I personally still use the Windows calculator application for this most of the time.
07:35 I find it less error prone and much faster so I encourage you to do the same.