![]() ![]() ![]() If you see a series of four binary digits with only one 1, then you simply run right to left counting by powers of 2. Okay, so we know that we can convert an arbitrarily large number by breaking it into single hex digits, but how do we convert a single hex digit to its equivalent four binary digits and vice versa? Well, let's start with the easy ones.Įach of the four binary digits in isolation are a power of two. It might be tough to know what F5 hex is in decimal (245), but we don't need to know that to do these conversions!Ĭonverting a single hex digit back and forth To give you an example, if we know that the number 0101 in binary is equivalent to 5 in hex, and 1111 in binary is equivalent to F in hex, then we can easily determine that 01011111 in binary is equivalent to 5F in hex, and 11110101 binary would be F5 hex. This means that we can convert any arbitrarily large number by simply breaking it down into chunks of four binary digits. You may notice that every combination of four binary digits is neatly contained in one hex digit. What do I mean by this? Take a look at the table below. The key trick to converting between hex and binary is to realize that one hex digit is perfectly equal to four binary digits. The key relationship between hex and binary This also means that in hex, the number 10 is actually the number 16 in base 10 (usually we would say 16 in decimal). How do we store more than ten values in a given digit? We use letters! In other words, the number 10 in hex becomes A, 11 becomes B, 12 becomes C, 13 becomes D, 14 becomes E, and 15 becomes F. Similarly, hex is also just a number system with a different base: 16. In computer science, we will usually group these numbers into groups of 8 (aka a Byte). Because the base is so low, binary numbers can be extremely long and intimidating to read (the number 51 in binary is 00110011). This means each digit can only store 2 values (usually notated as a 1 or a 0). For example, in base 10 (aka what we usually think of numbers in) one digit can store 10 different values (0-9).īinary is a number system in base 2. Even if you don't regularly go down to that low of a level, it can be extremely helpful when learning about lower level systems that you are building on top of, and can be invaluable when you do need to work in binary/hex.īefore we talk about how to convert between binary and hex, let's talk about what binary and hex are.Ī number base is the amount of values that can be stored in one digit. Being able to convert a number between hexadecimal and binary in your head is a really valuable skill in the world of computer science.
0 Comments
Leave a Reply. |