Apendix A: Numbering Systems
Introduction to Numbering Systems in Programming
Beginning programmers often struggle with binary and hexadecimal numbering systems due to the familiarity with the decimal system.
Understanding binary and hexadecimal can clarify complex topics such as Boolean algebra and character codes.
Numbering Systems Overview
PCs utilize a binary numbering system (base 2) instead of the familiar decimal system (base 10).
Familiarity with decimal, binary, and hexadecimal systems is crucial when programming.
Decimal Numbers
Decimal (base 10) uses ten symbols: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9.
Each value below ten is represented with a single digit. Values larger than ten require more digits (e.g., 10, 100, etc.).
Columns represent positional values based on powers of 10. For instance:
123 = 1 (hundreds) + 2 (tens) + 3 (ones).
Commas separate every three digits for readability in large numbers (e.g., 123,456,789).
Binary Numbers
Binary (base 2) comprises two symbols: 0 and 1.
Digital computers use binary representation because electronic circuits correspond to ON (1) and OFF (0).
Each position in a binary number reflects a power of 2.
Binary numbers are often spaced every four bits for readability (e.g., 1010 1111).
Hexadecimal Numbers
Hexadecimal (base 16) uses sixteen symbols: 0-9 and A-F, with A-F representing values 10-15.
Hexadecimal simplifies large binary values, allowing representation of vast numbers in fewer digits (e.g., 11111011 in binary can be represented as FB in hexadecimal).
Hexadecimal numbers begin with 0 and end with an 'h' to denote their base.
Spaces are added every four digits in hexadecimal for ease of reading.
Number System Conversions
Students must learn to convert between decimal, binary, and hexadecimal numbering systems.
Converting Binary to Decimal
Separate the binary number into columns.
Write the positional powers of 2 above each digit (1's, 2's, 4's, etc.).
Discard columns with zeros and add the remaining positional values to achieve the decimal equivalent.
Example: Binary 1001 converts to Decimal 9.
Converting Decimal to Binary
Use long division to convert a decimal number into binary:
Divide by 2 and take note of the remainder.
Continue with the quotient until it equals zero, recording remainders from bottom to top.
Example: Decimal 13 converts to binary as follows:
13 ÷ 2 = 6 r1
6 ÷ 2 = 3 r0
3 ÷ 2 = 1 r1
1 ÷ 2 = 0 r1
Final binary is 1101.
Converting Hexadecimal to Decimal
Write positional values for a hexadecimal number, which are powers of 16.
Multiply each hexadecimal digit by its column value, sum the products for the decimal equivalent.
Example: 0239H = (2256) + (316) + (9*1) = 512 + 48 + 9 = 569.
Converting Decimal to Hexadecimal
Apply long division by 16 similar to decimal to binary, recording the remainders from right to left.
For remainders between 10-15, convert to A-F.
Example: Decimal 569 divided by 16 gives a hexadecimal of 389.
Converting Binary to Hexadecimal
Group binary bits into sets of four, padding with zeros as needed (e.g., 111 becomes 0111).
Each group corresponds to a single hexadecimal character.
Converting Hexadecimal to Binary
Each hexadecimal digit corresponds to a four-bit binary number.
For example, hexadecimal A becomes binary 1010.
ASCII Character Set
ASCII stands for American Standard Code for Information Interchange.
Standard ASCII consists of 128 characters, including letters, numbers, punctuation, and control characters.
Control characters (0-31) were used historically for printing control.
ASCII supports uppercase letters (65-90), lowercase letters (97-122), and various punctuation marks.
Extended ASCII offers an additional 128 characters due to modern computer byte representation.
Data Types in Programming
Data items in programming are stored and manipulated as bits (binary digits).
Bits grouped together create symbols, often in bytes (8 bits).
Key data types:
Character Type: Signed (range of -128 to 127) and Unsigned (0 to 255).
Boolean Type: True or False (1 or 0).
Integer Type: Can be Signed (positive or negative) or Unsigned (only positive).
Floating Point: Represents numbers with fractional parts (e.g., 3.14). Floating-point numbers can be Float or Double.
Floating-point representation often mirrors scientific notation for large/small number representations.