Advanced Binary for Programming & Computer Science:
Logical, Bitwise and Arithmetic Operations, and Data Encoding and Representation
Copyright & Other Notices
Published in 2018 by Answers 2000 Limited
Copyright 2018, Sunil Tanna
Sunil Tanna has asserted his right to be identified as the author of this Work in accordance with the Copyright, Designs, and Patents Act 1988.
Information in this book is the opinion of the author, and is correct to the best of the author's knowledge, but is provided "as is" and without warranty to the maximum extent permissible under law. Content within this book is not intended as legal, tax, financial, medical, or any other form of professional advice.
While we have checked the content of this book carefully, in any educational book there is always the possibility of typographical errors, or other errors or omissions. We apologize if any such errors are found, and would appreciate if readers inform of any errors they might find, so we can update future editions/updates of this book.
Answers 2000 Limited is a private limited company registered in England under company number 3574155. Address and other information about information about Answers 2000 Limited can be found at www.ans2000.com
Updates, news & related resources from the author can be found at http://www.suniltanna.com/abinary
Information about other computing books by the same author can be found at http://www.suniltanna.com/computing
Information about math books by the same author can be found at http://www.suniltanna.com/math
Table of Contents
Introduction
Chapter 1: Introducing Number Bases and Binary
Chapter 2: Converting from Binary to Denary and Vice-versa
How to Convert a Binary Number to Denary
How to Convert a Denary Number to Binary
Questions
Answers to Chapter 2 Questions
Chapter 3: How Computers Group Binary Digits
A Closer Look at Bytes
A Closer Look at Words
- Word alignment
- Word alignment and packing
- Byte ordering and endianness
Addresses
Chapter 4: Boolean Operations and Logic Gates
Fundamentals of Boolean Algebra
- Boolean operation: NOT
- Boolean operation: AND
- Boolean operation: OR
- Boolean operation: XOR
- Boolean operation: NAND
- Boolean operation: NOR
- Boolean operation: NXOR
Combining Logic Gates
- NOT using NAND logic
- AND using NAND logic
- OR using NAND logic
- XOR using NAND logic
- NOR using NAND logic
Logical Versus Bitwise Operations
Using Bitwise Operations to Set, Clear, Flip or Test Bits
- Setting bits
- Inverting bits
- Clearing bits
- Testing bits
Questions
Answers to Chapter 4 Questions
Chapter 5: Adding and Subtracting in Binary
Adding Binary Integers
- The column addition method of adding denary numbers
- The column addition method of adding binary numbers
- Implementing binary addition using logic gates
Subtracting Binary Integers
- The column subtraction method of subtracting denary numbers
- The column subtraction method of subtracting binary numbers
- Implementing binary subtraction using logic gates
Questions
Answers to Chapter 5 Questions
Chapter 6: Shift Operations
Left Shift
Right Shift
Circular Shifts
Questions
Answers to Chapter 6 Questions
Chapter 7: Multiplication and Division in Binary
Multiplication
- Multiplying by a power of 2
- Column multiplication
- Russian peasant multiplication algorithm
- Multiplication in hardware
Division
- Dividing by a power of 2
- Denary long division
- Binary long division
- Algorithm for binary long division
- Division in hardware
Questions
Answers to Chapter 7 Questions
Chapter 8: Representing Characters and Strings of Characters
Representing Individual Characters
- ASCII
- Extended ASCIIs
- BCDIC and other early character encodings
- EBCDIC
- Unicode
Representing Strings of Characters
- Terminated strings
- Length-prefixed strings
- Other string representations
Chapter 9: Representing Text and Graphics on Screen
Text Mode Displays
Bitmap Displays
Chapter 10: Parity Checking
What is a Parity Bit
Even and Odd Parity
Advantages, Disadvantages and Limitations of Using Parity Checking
Parity's Use in RAID Storage Devices
Unused Parity Bits
Questions
Answers to Chapter 10 Questions
Chapter 11: Signed Integers
Offset Binary
Signed Magnitude Representation
One's Complement
Two's Complement
Other Representations of Signed Numbers
- Base -2
- Signed-digit representation
Chapter 12: Real Numbers
Fixed Point Representation
Floating Point Representation
Rational Data Type
Logarithmic Number Systems
Chapter 13: Denary Encodings and Decimal Data Types
Why Use Denary Representations of Real Numbers?
Binary Encodings of Denary
- Serial decimal
- Two-out-of-five
- Bi-quinary
- Character-based encodings of denary
- Binary-Coded Decimal (BCD)
- Chen-Ho Encoding
- Densely Packed Decimal (DPD)
- Excess-3
Decimal Data Types
- Which numbers can be exactly represented in fixed and floating point?
- How inexact?
- Issues with inexact representation
- Decimal representation
Chapter 14: Data Structures
Structs
Arrays
Linked Lists and More Complex Structures
- Limitations of arrays
- Introducing linked lists
- Singly and doubly linked lists
- More complex data structures
Chapter 15: Types of Computer Memory
Magnetic-Core Memory and Core Rope Memory
RAM
ROM
- Mask-programmed ROM
- PROM
- EPROM
- EEPROM
- Flash memory
Chapter 16: Secondary Storage
Sequential Storage
- Punched tape
- Magnetic tape
Random Access Storage
- Magnetic disk
- Optical disk
- Solid state drives and flash memory
- Cloud Storage
Chapter 17: Measuring Memory and Storage
Chapter 18: Digital Communications
Serial Communication
Parallel Communication
Chapter 19: Measuring Transfer Rates
Baud
Conclusion
Introduction
This book explains how the binary number system works and how it is used by digital computers to represent information including positive and negative integers, characters and real numbers. It also explains logical and bitwise operations that computers use to manipulate information and perform arithmetic. Finally, we also briefly look at how computers store this information in memory and secondary storage, and how it can be transmitted between computers.
No prior knowledge except a general familiarity with basic arithmetic and mathematics (including the use of fractions, decimals and exponents) is assumed by this book.