Difference between revisions of "Computer Number Systems"

From ACSL Category Descriptions
Jump to navigation Jump to search
(37 intermediate revisions by 3 users not shown)
Line 1: Line 1:
All digital computers – from supercomputers to your smartphone – ultimately can do one thing: detect whether an electrical signal is on or off. That information is called a ''bit'' ('''bi'''nary digi'''t''') and has two values, a 1 (or ''true'') when the signal is on, and a 0 (of ''false'') when the signal is off. Larger values can be stored by a group of bits. For example, 3 bits together can take on 8 different values.  
All digital computers – from supercomputers to your smartphone – ultimately can do one thing: detect whether an electrical signal is on or off.  
That basic information, called a ''bit'' ('''bi'''nary digi'''t'''), has two values: a 1 (or ''true'') when the signal is on, and a 0 (of ''false'') when the signal is off. Larger values can be stored by a group of bits. For example, 3 bits together can take on 8 different values.  


Computer scientists use the binary number system (that is, base 2) to represent the values of bits. Proficiency in the binary number system is essential to understanding how how numbers and information is represented in a computer. Since binary numbers representing moderate values quickly become rather lengthy, bases eight (octal) and sixteen (hexadecimal) are frequently used as shorthand.
Computer scientists use the [https://en.wikipedia.org/wiki/Binary_number binary number system] (that is, base 2) to represent the values of bits. Proficiency in the binary number system is essential to understanding how numbers and information are represented in a computer. Since binary numbers representing moderate values quickly become rather lengthy, bases eight ([https://en.wikipedia.org/wiki/Octal octal]) and sixteen ([https://en.wikipedia.org/wiki/Hexadecimal hexadecimal]) are frequently used as shorthand. In octal, groups of 3 bits form a single octal digit; in hexadecimal, groups of 4 bits form a single hex digit.


== Binary, Octal ==
In this category, we will focus on conversion between binary, octal, decimal, and hexadecimal numbers. There may be some arithmetic in these bases, and occasionally, a number with a fractional part. We will not cover how negative numbers or floating point numbers are represented in binary.
 
A binary number consists of two symbols, 0 and 1. The value of a binary number is found by looking at the bit in each position and multiplying it by the value of that position.
== Resources ==
 
[https://ryanstutorials.net/ Ryan's Tutorials] covers this topic beautifully. Rather than trying to duplicate that work, we'll point you to the different sections:


For example, the binary number 101011 has a decimal value of $1 \cdot 2^5 + 0 \cdot  2^4 + 1 cdot 2^3 + 0 \cdot  2^2 + 1\cdot 2^1 + 1 \cdot 2^0 = 32+ 0+8 + 0 +2 + 1 = 43$.
:[https://ryanstutorials.net/binary-tutorial/ 1. Number Systems] - An introduction to what numbers systems are all about, with emphasis on decimal, binary, octal, and hexadecimal. ACSL will typically identify the base of a number using a subscript. For example, $123_8$ is an octal number, whereas $123_{16}$ is a hexadecimal number.  


The binary number 101111010000110 has a decimal value of 24,198.
:[https://ryanstutorials.net/binary-tutorial/binary-conversions.php 2. Binary Conversions] - This section shows how to convert between binary, decimal, hexadecimal and octal numbers. In the [https://ryanstutorials.net/binary-tutorial/binary-conversions.php#activities ''Activities''] section, you can practice converting numbers.  


:[https://ryanstutorials.net/binary-tutorial/binary-arithmetic.php 3. Binary Arithmetic] - Describes how to perform various arithmetic operations (addition, subtraction, multiplication, and division) with binary numbers. ACSL problems will also cover basic arithmetic in other bases, such as adding and subtracting together 2 hexadecimal numbers. ACSL problems will not cover division in other bases.


The decimal number of 24,198 is the binary number 101111010000110.  
:[https://ryanstutorials.net/binary-tutorial/binary-negative-numbers.php 4. Negative Numbers] - ACSL problems will not cover how negative numbers are represented in binary.  


Each group of 4 bits has 16 different values: 0 through 15. For example, 1011 has a decimal value of $1\cdot 2^3 + 0\cdot 2^2 + 1 \cdot 2^1 + 1 \cdot 2^0 = 8+0+2+1 = 11$.
:[https://ryanstutorials.net/binary-tutorial/binary-floating-point.php 5. Binary Fractions and Floating Point] - The first part of this section is relevant to ACSL: fractions in other bases. ACSL will not cover floating point numbers in other basis. So, focus on the section [https://ryanstutorials.net/binary-tutorial/binary-floating-point.php#convertfraction Converting to a Binary Fraction], but keep in mind that ACSL problems may also cover octal and hexadecimal fractions.


Large numbers quickly become quite cumbersome to deal with in binary (for example, a value of 1 million is a binary number that is 20 bits in length), so each group of 4 bits can be represented by a base 16 digits, 0, 1, 2, 3, 4, 5, 6, 7, 8 9, A, B, C, D, E, or F.  
The  [https://coolconversion.com/math/binary-octal-hexa-decimal/ CoolConversion.com online calculator] is another online app for practicing conversion from/to decimal, hexadecimal, octal and binary; this tool shows the steps that one goes through in the conversion.


For example, the binary  number  101111010000110 can be written as 101 1110 1000 0110, which
== Format of ACSL Problems ==
101 1110 1000 0110


1 x 2^$101101_2$ (the subscript is optional, if the context makes it clear that  for example 1011 and 10110. The value of a binary number is found by Often, we'll use a subscript of ''2'' to be explicit that the number is in base 2.
The problems in this category will focus on converting between binary, octal, decimal, and hexadecimal, basic arithmetic of numbers in those bases, and, occasionally, fractions in those bases.
.  Octal numbers group binary numbers in bunches of 3 digits and convert the triplet to a single digit between 0 and 7, inclusive.


For example, 10010101102 = 001 001 010 1102 = 11268. 
To be successful in this category, you must know the following facts cold:


This is because 8 = 23 and the value of three bits 111 = 1 + 2 + 4 = 7 using powers of 2.  
# The decimal value of each hex digit A, B, C, D, E, F 
# The binary value of each hex digit A, B, C, D, E, F
# Powers  of  2,  up  to 4096
# Powers  of  8,  up  to 4096
# Powers  of  16,  up  to  65,536


Hexadecimal numbers group binary numbers by fours, and convert the quadruplet to a single digit in the range 0, 1, 2 …, 9, A, B, C, D, E, F.  The digits A through F have decimal values of 10 through 15 respectively.  This is because 16 = 24 and the value of four bits 1111 = 1 + 2 + 4 + 8 = 15 using powers of 2. 
== Sample Problems ==


For example, 101101101001012 = 0010 1101 1010 01012 = 2DA516. 
=== Sample Problem 1 ===


Solve for $x$ where $x_{16}=3676_8$.


All of the basic rules of number theory apply to every base, but these three bases 2, 8, and 16 are uniquely suited for computer science.
'''Solution:''' One method of solution is to convert $3676_8$ into base 10, and then convert that number into base 16 to yield the value of $x$.


Therefore, converting from any base to base 10 involves multiplying each digit by an increasing power of that base. 
An easier solution, less prone to arithmetic mistakes, is to convert from octal (base 8) to hexadecimal (base 16) through the binary (base 2) representation of the number:
$$\begin{align}
3676_8 &= 011 ~  110 ~ 111 ~ 110_2  & \text{convert each octal digit into base 2}\hfill\cr
&= 0111 ~ 1011 ~ 1110_2  & \text{group by 4 bits, from right-to-left}\hfill\cr
&= 7 ~ \text{B} ~ \text{E}_{16}  & \text{convert each group of 4 bits into a hex digit}\cr
\end{align}$$


For example, 457_8 = 7 x 8^0 + 5 x 8^1 + 4 x 8^2 = 7 + 40 + 256 = 30310. 
=== Sample Problem 2 ===


Converting from base 10 to any other base involves finding how many times each decreasing power of that base can be divided evenly into the number and repeating the process with the remainder.  For example, 50010 = 256 x 1 + 16 x 15 + 1 x 4 = 1F416.  Another way to accomplish this is to repeatedly divide the number by the base as follows:
Solve for $x$ in the following hexadecimal equation: $ x= \text{F5AD}_{16} - \text{69EB}_{16}$


 
'''Solution:''' One could convert the hex numbers into base 10, perform the subtraction, and then convert the answer back to base 16. However,
Therefore, reading the remainders from bottom to top give you 1F416.
working directly in base 16 isn't too hard.
As in conventional decimal arithmetic, one works from right-to-left, from the least significant digits to the most.


Adding in bases other than 10 means that you must carry the value of that base and subtracting in bases other than 10 means that you must borrow the value of that base if necessaryFor example:
:The rightmost digit becomes 2, because D-B=2. 
:The next column is A-E. We need to ''borrow'' a one from the 5 column, and 1A-E=C
:In the next column, 4-9=B, again, borrowing a 1 from the next column.
:Finally, the leftmost column, E-6=8


 
Combining these results of each column, we get a final answer of $8BC2_{16}$.


since D=13 and 13+3=16 so leave the 0 and carry the 16 as a 1.  Then E=14 and A=10 so 1+14+10 = 25 so leave the 9 and carry the 16 as a 1.  E=14 so 1+14+9=24 so leave the 8 and carry the 16 as 1.  Finally, F=15 so 1+15=16 which is 10.
=== Sample Problem 3 ===


Subtracting in base 8 is as follows:   
How many numbers from 100 to 200 in base 10 consist of distinct
ascending digits and also have distinct ascending hex digits when
converted to base 16?


Borrow 1=8 from the 7 since 2+8-6=4Therefore, 6–5=1.  Then, borrow 1=8 from the 4 since 5+8–7=6.  Then the last digit on the left is a 3.
'''Solution:''' There are 13 numbers that have ascending digits in both bases from 100
to 200They are (in base 10):
123 (7B), 124, 125, 126, 127 (7F), 137 (89), 138, 139 (8B), 156 (9C), 157, 158, 159 (9F), 189 (BD)


== Video Resources ==


== Format of Problems ==
There are many YouTube videos about computer number systems. Here are a handful that cover the topic nicely, without too many ads:


The  key  here  is  to  convert  between  hexadecimal  (base  16)  and  octal  (base  8);  using  the  binary  representation  is  often  easier  than  going  through  base  10.  Some  problems  require  simple  arithmetic  in  hexadecimal  and  octal,  and  once  in  a  while  you’ll  see  of  “decimal  point”. 
{|


Facts  you  must  know  cold:
|-
#The  values  of  hex  digits  A,  B,  C,  D,  E,  F 
| <youtube width="300" height="180">https://youtu.be/aW3qCcH6Dao</youtube>
# Powers  of  2,  up  to,  say,  4096 
| [https://youtu.be/aW3qCcH6Dao ''Number Systems - Converting Decimal, Binary and Hexadecimal'' ('''Joe James''')]
# Powers  of  8,  up  to  say,  4096 
# Powers  of  16,  up  to  say,  65,536
#.Convert  from  base  16  to  base  2, and vice  versa 
# Convert  from  base  8  to  base  2,  and  vice  versa
# Convert between octal and hex, via base 2


== External Resources ==
An introduction to number systems, and how to convert between decimal, binary and hexadecimal numbers.


This Binary tutorial is divided into 3 sections. In general I recommend you work through them in order but if you've come here just to learn about a specific topic then who am I to slow you down, just head straight on over.
|-
| <youtube width="300" height="180">https://youtu.be/m1JtWKuTLR0</youtube>
| [https://youtu.be/m1JtWKuTLR0 ''Lesson 2.3 : Hexadecimal Tutorial'' ('''Carl Herold''')]


Number Systems - Read on below to discover the theory behind numbers.
The video focuses on hexadecimal numbers: their relationship to binary numbers and how to convert to decimal numbers.  
Conversions - How to convert between binary and decimal, hexadecimal and octal.
Arithmetic - Learn how to perform various arithmetic operations with binary numbers.
Negative Numbers - Learn how to manage negative numbers in binary.
Floating point and fractions - Learn how to convert decimal numbers to and from binary fractions and floating point.


Binary Tutorial - 1. Number Systems
|-
https://ryanstutorials.net/binary-tutorial/
| <youtube width="300" height="180">https://youtu.be/WR67syBDzew</youtube>
| [https://youtu.be/WR67syBDzew ''Hexes and the Magic of Base 16 - Vaidehi Joshi - May 2017' ('''DonutJS''')]


A fun introduction to hexadecimal numbers, focusing a bit
on using hex numbers for specifying RGB colors.


https://ryanstutorials.net/binary-tutorial/binary-conversions.php
|-
Binary Tutorial - 2. Binary Conversions
| <youtube width="300" height="180">https://youtu.be/jvx-NrILgpE</youtube>
| [https://youtu.be/jvx-NrILgpE ''Collins Lab: Binary & Hex'' ('''Adafruit Industries''')]


Binary Tutorial - 3. Binary Arithmetic
A professionally produced video that explains the number systems, how and why binary numbers are fundamental to computer science, and why hexadecimal is important to computer programmers.
https://ryanstutorials.net/binary-tutorial/binary-arithmetic.php


Binary Tutorial - 5. Binary Fractions and Floating Point
|}
https://ryanstutorials.net/binary-tutorial/binary-floating-point.php

Revision as of 22:02, 20 August 2018

All digital computers – from supercomputers to your smartphone – ultimately can do one thing: detect whether an electrical signal is on or off. That basic information, called a bit (binary digit), has two values: a 1 (or true) when the signal is on, and a 0 (of false) when the signal is off. Larger values can be stored by a group of bits. For example, 3 bits together can take on 8 different values.

Computer scientists use the binary number system (that is, base 2) to represent the values of bits. Proficiency in the binary number system is essential to understanding how numbers and information are represented in a computer. Since binary numbers representing moderate values quickly become rather lengthy, bases eight (octal) and sixteen (hexadecimal) are frequently used as shorthand. In octal, groups of 3 bits form a single octal digit; in hexadecimal, groups of 4 bits form a single hex digit.

In this category, we will focus on conversion between binary, octal, decimal, and hexadecimal numbers. There may be some arithmetic in these bases, and occasionally, a number with a fractional part. We will not cover how negative numbers or floating point numbers are represented in binary.

Resources

Ryan's Tutorials covers this topic beautifully. Rather than trying to duplicate that work, we'll point you to the different sections:

1. Number Systems - An introduction to what numbers systems are all about, with emphasis on decimal, binary, octal, and hexadecimal. ACSL will typically identify the base of a number using a subscript. For example, $123_8$ is an octal number, whereas $123_{16}$ is a hexadecimal number.
2. Binary Conversions - This section shows how to convert between binary, decimal, hexadecimal and octal numbers. In the Activities section, you can practice converting numbers.
3. Binary Arithmetic - Describes how to perform various arithmetic operations (addition, subtraction, multiplication, and division) with binary numbers. ACSL problems will also cover basic arithmetic in other bases, such as adding and subtracting together 2 hexadecimal numbers. ACSL problems will not cover division in other bases.
4. Negative Numbers - ACSL problems will not cover how negative numbers are represented in binary.
5. Binary Fractions and Floating Point - The first part of this section is relevant to ACSL: fractions in other bases. ACSL will not cover floating point numbers in other basis. So, focus on the section Converting to a Binary Fraction, but keep in mind that ACSL problems may also cover octal and hexadecimal fractions.

The CoolConversion.com online calculator is another online app for practicing conversion from/to decimal, hexadecimal, octal and binary; this tool shows the steps that one goes through in the conversion.

Format of ACSL Problems

The problems in this category will focus on converting between binary, octal, decimal, and hexadecimal, basic arithmetic of numbers in those bases, and, occasionally, fractions in those bases.

To be successful in this category, you must know the following facts cold:

  1. The decimal value of each hex digit A, B, C, D, E, F
  2. The binary value of each hex digit A, B, C, D, E, F
  3. Powers of 2, up to 4096
  4. Powers of 8, up to 4096
  5. Powers of 16, up to 65,536

Sample Problems

Sample Problem 1

Solve for $x$ where $x_{16}=3676_8$.

Solution: One method of solution is to convert $3676_8$ into base 10, and then convert that number into base 16 to yield the value of $x$.

An easier solution, less prone to arithmetic mistakes, is to convert from octal (base 8) to hexadecimal (base 16) through the binary (base 2) representation of the number:

$$\begin{align} 3676_8 &= 011 ~ 110 ~ 111 ~ 110_2 & \text{convert each octal digit into base 2}\hfill\cr &= 0111 ~ 1011 ~ 1110_2 & \text{group by 4 bits, from right-to-left}\hfill\cr &= 7 ~ \text{B} ~ \text{E}_{16} & \text{convert each group of 4 bits into a hex digit}\cr \end{align}$$

Sample Problem 2

Solve for $x$ in the following hexadecimal equation: $ x= \text{F5AD}_{16} - \text{69EB}_{16}$

Solution: One could convert the hex numbers into base 10, perform the subtraction, and then convert the answer back to base 16. However, working directly in base 16 isn't too hard. As in conventional decimal arithmetic, one works from right-to-left, from the least significant digits to the most.

The rightmost digit becomes 2, because D-B=2.
The next column is A-E. We need to borrow a one from the 5 column, and 1A-E=C
In the next column, 4-9=B, again, borrowing a 1 from the next column.
Finally, the leftmost column, E-6=8

Combining these results of each column, we get a final answer of $8BC2_{16}$.

Sample Problem 3

How many numbers from 100 to 200 in base 10 consist of distinct ascending digits and also have distinct ascending hex digits when converted to base 16?

Solution: There are 13 numbers that have ascending digits in both bases from 100 to 200. They are (in base 10): 123 (7B), 124, 125, 126, 127 (7F), 137 (89), 138, 139 (8B), 156 (9C), 157, 158, 159 (9F), 189 (BD)

Video Resources

There are many YouTube videos about computer number systems. Here are a handful that cover the topic nicely, without too many ads:

Number Systems - Converting Decimal, Binary and Hexadecimal (Joe James)

An introduction to number systems, and how to convert between decimal, binary and hexadecimal numbers.

Lesson 2.3 : Hexadecimal Tutorial (Carl Herold)

The video focuses on hexadecimal numbers: their relationship to binary numbers and how to convert to decimal numbers.

Hexes and the Magic of Base 16 - Vaidehi Joshi - May 2017' (DonutJS)

A fun introduction to hexadecimal numbers, focusing a bit on using hex numbers for specifying RGB colors.

Collins Lab: Binary & Hex (Adafruit Industries)

A professionally produced video that explains the number systems, how and why binary numbers are fundamental to computer science, and why hexadecimal is important to computer programmers.