This chapter discusses numbering systems and shows how the computer stores numbers. Manually converting between decimal, binary, and hexadecimal is demonstrated using the remainder and positional methods. Using Python to convert from the three bases, and how to enter integers into your program in the various bases I also shown.

Objectives

Upon completion of this chapter’s exercises, you should be able to:

  • Recognize decimal, binary, and hexadecimal numbers.
  • Define binary and hexadecimal constant numbers in Python using the 0b or 0x prefix.
  • Convert numbers from decimal to binary and hexadecimal using the remainder method.
  • Calculate the decimal value from a binary or hexadecimal number using the positional method.
  • Use Python’s built in functions to convert decimal numbers to strings containing binary and hexadecimal.
  • Perform the operations of addition and subtraction of binary numbers, using the twos’ compliment when necessary.