Main content

## Algebra (all content)

### Course: Algebra (all content) > Unit 1

Lesson 14: Binary and hexadecimal number systems- Introduction to number systems and binary
- Hexadecimal number system
- Converting from decimal to binary
- Converting larger number from decimal to binary
- Converting from decimal to hexadecimal representation
- Adding in binary
- Multiplying in binary
- Converting directly from binary to hexadecimal

© 2023 Khan AcademyTerms of usePrivacy PolicyCookie Notice

# Converting directly from binary to hexadecimal

## Want to join the conversation?

- At2:14, why does he take 4 places? Why not less? Why not more?(6 votes)
- as 16 is 2 to the power of 4, thus he takes 4 places(9 votes)

- Can the reverse be done?
`(hex) to (bin)`

And what happens when the number is a decimal (E.g. 101.01)?(4 votes)- 1) Yes, the reverse can be done (hint: read up the "blackboard" instead of down).

2) is the number has a (WARNING: math jargon approaching...) a radix point, you can work it directly - just ignore the dot when you make your answer, then put it back in the place you took it from - or convert it to decimal, and then go from decimal to your desired base.(5 votes)

- I think the best way to pronounce numbers with a base bigger than 10 is to simply say the individual numbers. For 16E, just say, "one-six-E." That's what Science Bowl proctors did, anyway.(5 votes)
- Is it still "converting directly" If you have to count in decimal system to work out how many e.g. 1s there are?(3 votes)
- He is counting in decimal to help the viewers understand why it works. Normally, you would see a binary pattern, say 1101, and add them in base-16. 8+4 = C, and C+1 = D, so 1101 (binary) = D (hexadecimal). Or if you have a hexadecimal number, say FC9, you would do the process in reverse. F = 8+4+2+1 and that is equal to 1111 in binary. C = 8+4. So FC9 (hex) = 1111 1100 1001.

Don't confuse those "8+4+2+1" as decimal, they are in fact hexadecimal. 8+4 = C, then C+2=E, and then E+1=F. Notice that not once throughout the explanation I used decimal numbers, so I can convert any hexadecimal number to binary number and vice versa without even knowing what those numbers are in decimal.(3 votes)

- I don't really get how the sixteens and the 256s place are between 0-F(2 votes)
- - sixteens can take values from 0x16 up to Fx16

- so are 256s(16²) which can take values from 0x16² up to Fx16²

- so is any position of power of sixteen which will always take values multiplied by 0 up to F(4 votes)

- Are there ways to convert directly from any base x to any base y where y is not 10 or a power of x like for example base 2 -> base 3?(2 votes)
- Sure, digit m of number x in base b is just: x mod b^m where mod is the remainder function that gives the rest of the division (so 27 mod 17 its 10, for example).(1 vote)

- How do you convert a number from BASE-16 to BASE-2 or BASE-4(2 votes)
- You reverse the process. Each base-16 digit becomes four binary digits:

e.g. 159E_16 = 0001 0101 1001 1110_2

The process for base four is similar, only each base four digit is 2 bits:

0123_4 = 00011011_2 = 1B_16. I find it easier to convert to binary and back to hex, as you see here. This shows one way of noting one byte, or eight bits.

I use _16 to denote base 16 and _2 to denote base 2 here.(1 vote)

- How do you convert 1.63 into BASE-16?(2 votes)
- what is the coversion of k in any other number system(1 vote)
- why you added the third octet? was it necessary to solve it with the third octet? lets pretend you didn't add the third octet ...what would be the answer? 1 6 E ? perhaps? let me know sir..(1 vote)

## Video transcript

- [Voiceover] What I would
like to do in this video is explore the connection between
the binary number system which is clearly, or we've already talked about this, is base two. Explore the quotient between
that and the hexadecimal, hexadecimal number
system, which is base 16. The reason why this is interesting is because 16 is a power of two. What we'll see is you could always view the hexadecimal number system. It's almost condensed representation of the binary number system. This is actually why you will actually, we've already talked
about the binary system is used extensively in computer science and in even computer engineering. It's the underlying
things that are happening or it's the representation
used when we talk about logic gates and
transistors and things like that. But hexadecimal also shows up a lot because it's kind of a condensed
representation of base two. What do I mean by that? Let's write out a arbitrary
number in base two. Let's say I have one, zero, one, one, zero, one, one, one, zero. This right over here is in binary and I can even write in parenthesis . This is a binary representation. I want to convert this to
hexadecimal representation. I encourage you to pause the
video and try out in your own. I'll give you a clue
on how you could think about converting directly
from base two to base 16. Think about which one over
here is in the 16s place and what is the 256 place over here. Then that might help you convert directly. Assuming you had a go at it. The really fun thing about
between base two and base 16 is you don't have to, well for any
bases, you really don't have to go through base 10
but these in particular, it's especially easy to go
convert between these two bases. The realization that you have to make is, what are the powers, which
places here are powers of 16? This right over here,
that is the ones place. One way to think about it
is all of these is going to tell you how many ones we have. Ones, twos, fours, and eights, but another way to think
about it is this is a count of ones, all the way up
to a potential of 15 ones. This could count, this is
going to be between zero, and I'm going to write it down. Actually, let me write it down in base 16. It's going to be between zero and F. It's going to be between zero and 15. It's kind of a count between the number of ones, I guess you could say. Then this is the 16s place. I'm going to do that in different color. This right over here is the 16s place. You could have between zero and 15s, 16s. This is also going to
be between zero and F, when you look at this
four digit binary numbers. Once again, this whole
thing right over here is essentially going to tell
you how many 16s you have. This whole thing is going to tell you how many ones you have. Then the next four, we could keep going, although there is only one place here. We could go, this right
over here is the 256s place. This is going to be the next four digits. They really have one right over here, but one, two, three,
and then the fourth one. This is also going to be
between zero and 15, 256s. Hopefully, that helps you a little bit. Actually, if this was
a clue, I encourage you to pause the video again (laughs) and see if you can represent this in hexadecimal. Let's try to work this thing together. How many ones do we have? What number is this? These four digits right over here. This is eight plus four plus two. So eight plus four is 12, plus two is 14. This right over here is 14. How do we represent that in hexadecimal? Well, 14 is one less than
15 so it's going to be E. This is going to be E. This is E. E is our hexadecimal
representation of the number 14 comes right before our
representation of the number 15 F. Alright, now, how many 16s do we have? Let's see, I have no eights. I have a four, and I have a two. We're going to have six 16s. So we're going to have six 16s. Then, how many 256s do I have? I only have one 256. One 256. This number in hexadecimal,
and I could write that. This is in hexadecimal right
over here, is one, six, E. One, six, E. I guess you could call this 256 E, 16 E. I guess 14. I (laughs) finally have to
come up with a better way of reading this hexadecimal number. If you're not curious what
number is this, because you don't have to go through decimal
just so you could comprehend it in the number system that
you're used to operating in. One that's based off from the
number of fingers you have. Feel free to do so.