Difference between revisions of "Computer Number Systems"

From ACSL Category Descriptions
Jump to navigation Jump to search
Line 13: Line 13:


:[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-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.  
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.
 
:[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.
:[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.


Line 20: Line 19:


:[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 hexadicmal fractions.
:[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 hexadicmal fractions.
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.


== Basics ==  
== Basics ==  

Revision as of 08:23, 4 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 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. In octal, groups of 3 bits form a single octal digit; in hexadecimal, group 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 are represented in binary.

Resources

[Ryan's Tutorials] covers this topic in 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 hexadicmal 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.

Basics

Evaluation of binary, octal, and hex numbers

The binary number system 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. For example, the binary number 101011 has a decimal value of $$ {\bf 1} \cdot 2^5 + {\bf 0} \cdot 2^4 + {\bf 1} \cdot 2^3 + {\bf 0} \cdot 2^2 +{\bf 1} \cdot 2^1 + {\bf 1} \cdot 2^0 = 32+ 0+8 + 0 +2 + 1 = 43$$

The base 8 number system, octal, uses the symbols 0, 1, 2, 3, 4, 5, 6 and 7. To convert an octal number into decimal, simply multiply each digit by the value of that position. For example, the octal number 4170 has decimal value of $$ {\bf 4} \cdot 8^3+ {\bf 1} \cdot 8^2 + {\bf 7} \cdot 8^1 + {\bf 0} \cdot 8^0 = 4\cdot 512 + 1\cdot 64 + 7\cdot 8 + 0\cdot 1 = 2048+64+56+0=2168$$

The base 16 number system, hexadecimal, uses 16 symbols: the symbol 0 through 9, A, B, C, D, E, and F. The decimal value of a hex number follows the same pattern as we've just seen for determining the decimal value of a binary or octal number.

  • Step 1: Write down the hexadecimal number: $ 3AF _{16}$
  • Step 2: Write each hexit as an increasing power of 16: $ 3 \cdot 16^2 + A \cdot 16^1 + F \cdot 16^0 $
  • Step 3: Convert each hexit to decimal: $ 3\cdot 256 + 10\cdot 16 + 15\cdot 1 $
  • Step 4: Perform the math: $ 768 + 160 + 15 = 943$

Converting from decimal to binary, octal, and hex

The are fundamentally two ways to convert a base 10 into another base: finding powers and repeated division. Here is the conversion of 1375 into octal using these two methods.

Method 1: Finding powers. The powers of 8 are: 1, 8, 64, 512, 4096, .... SInce 4096 is larger than 1375, we know that the form of the octal number will be $a \cdot 512 + b \cdot 64 + c \cdot 8 + d$.

Step 1: How many times does the largest power of 8 go into the number: 1375 / 512 = 2, remainder of 351.
Step 2: How many times does the next smaller power of 8 go into the remainder: 351 / 64 = 5, remainder of 31.
Step 2 (again): How many times does the next smaller power of 8 go into the remainder: 31 / 8 = 3, remainder of 7.
Step 2 (again): How many times does the next smaller power of 8 go into the remainder: 7 / 1 = 7, remainder of 0.

At this point, the number can be read off: 2 * 512 + 5 * 64 + 3*8 + 7 = 2537 (base 8)

Method 2: Repeated Division.

Step 1: Divide (1375)10 successively by 8 until the quotient is 0:
1375/8 = 171, remainder is 7
171/8 = 21, remainder is 3
21/8 = 2, remainder is 5
2/8 = 0, remainder is 2
Step 2: Read from the bottom to top as 2537. This is the octal equivalent of decimal number 1375.

You can get lots of practice convert from/to decimal, hexadecimal, octal and binary using the [https://coolconversion.com/math/binary-octal-hexa-decimal/

CoolConversion.com online calculator].


(03AF)16

Step 2: Show each digit place as an increasing power of 16:

0x163 + 3x162 + Ax161 + Fx160

Step 3: Convert each hexadecimal digits values to decimal values then perform the math:

0x4096 + 3x256 + 10x16 + 15x1 = (943)10

So, the number 943 is the decimal equivalent of hexadecimal number 03AF (Answer).

https://coolconversion.com/math/binary-octal-hexa-decimal/

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$.

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.

For example, the binary number 101111010000110 can be written as 101 1110 1000 0110, which 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. . 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.

This is because 8 = 23 and the value of three bits 111 = 1 + 2 + 4 = 7 using powers of 2.

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.

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

https://en.wikipedia.org/wiki/Octal

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.

Therefore, converting from any base to base 10 involves multiplying each digit by an increasing power of that base.

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

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:


Therefore, reading the remainders from bottom to top give you 1F416.

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 necessary. For example:


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.

Subtracting in base 8 is as follows:


Borrow 1=8 from the 7 since 2+8-6=4. Therefore, 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.

Format of Problems

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:

  1. The values of hex digits A, B, C, D, E, F
  2. Powers of 2, up to, say, 4096
  3. Powers of 8, up to say, 4096
  4. Powers of 16, up to say, 65,536
  5. .Convert from base 16 to base 2, and vice versa
  6. Convert from base 8 to base 2, and vice versa
  7. Convert between octal and hex, via base 2

External Resources

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.

Number Systems - Read on below to discover the theory behind 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/


https://ryanstutorials.net/binary-tutorial/binary-conversions.php Binary Tutorial - 2. Binary Conversions

Binary Tutorial - 3. Binary Arithmetic 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

test

fooo