Computer Number Systems 101
Computer Number Systems 101
• This is called the binary number system. Each binary digit is referred
to as a bit. For instance, 01100110 is composed of 4-bits which
are 00, 11, 11, and 00. When it comes to placing values to the bits (i.e.
digits) in this system, we place values corresponding to ascending
powers of 2 from right to left.
• The rightmost bit is called the least significant bit (LSB), and
the leftmost bit is the most significant bit (MSB).
• You can manipulate bits left and right with bitwise operators
to efficiently change the value of a number at the machine
code level.
Convert between Decimal and
Binary
• We know that the binary system has place values of powers of 2.
These values are weights for the digits (0 or 1) in those positions.
Here’s how it works:
• We multiply each digit by its weight (its position multiplied by 2)
• We sum them all up to get the decimal number
• So, let’s take the binary number 11111010 and convert it to the
decimal number system.
• Now let’s try it the other way around. How do we convert from a
decimal to a binary number? One method to do this is repeated
division, which is a handy shortcut.
• o, take the number 19. We start by dividing it by two and writing
down the remainder. When we divide 19 by 2, we get 9 with a
remainder of 1.
• We then take 9 and divide it by 2, giving us a result of 4 with a
remainder of 1. This process continues until we reach zero. The
remainders that we gathered form our binary number!
Introduction to the
Hexadecimal Number
System
• The hexadecimal system is amore compact way of
representing numbers on a computer, as it requires only 4
bits to represent a digit’s value.
• The hexadecimal system (often called “hex”) is made up
of 16 symbols, so it has a base of 16. Hexadecimal uses the
10 numbers of the decimal system and six extra symbols, A,
B, C, D, E and F.
• The place values in hexadecimal are powers of 16. Let’s see
what the hexadecimal number XYZ would be in decimal. As
you can see below, hexadecimal numbers are preceded by a
# to indicate that they are base-16.
How to convert
between binary and
hexadecimal
• We will group the binary digits into sets of four (starting on the right).
Then, we replace each quartet with the corresponding hexadecimal
representation.
• Now for hexadecimal to binary! Let’s go through an example. Below,
we are expanding each hexadecimal digit by replacing it with its
equivalent binary quartet.
What is the octal
number system?
• The octal number system is not as widely used as hex of binary. It was
developed under the same idea as the hexadecimal system: to make
binary more compact.
• The octal system groups binary numbers into triplets instead of
quartets. So, the octal system is base-8, as 23=823=8.
• We use eight base symbols for the octal system that are borrowed
from the decimal system. Binary triplets can have values ranging
from 0−70−7.
• So, the place values will be ascending in powers of 88 from right to
left.
• To convert binary to octal, we follow this basic technique:
• Group the binary number into sets of three (similar to what we did
with hex)
• Bring each group of digits to a multiple of three by adding zeroes
• Write the corresponding octal symbol underneath each group
• You will now have an octal number
• Converting octal to binary is similar but a bit simpler:
• Write the binary representation for each octal digit
• Join those numbers together
• You will not have a binary number