Nintendo NES-001 User Guide - Page 33

Appendix A, Arithmetic And Logic

Page 33 highlights

Appendix A Arithmetic And Logic A.1 Numbering Systems The hexadecimal number system uses base 16 with digits 0-9 and A-F, where A represents 10 and F represents 15. The hexadecimal system is used frequently throughout this document and any numbers written in this format will be indicated by use of the prefixes $ and 0x (used interchangeably). For example, $2F = (2 * 16) + 15 = 47. The binary number system uses base 2 with digits 0 and 1. This system is also frequently used and any numbers written in this format will be indicated by use of the suffix b. For example 101111b = 32 + 8 + 4 + 2 + 1 = 47. A.2 Binary Coded Decimal (BCD) Binary Coded Decimal represents each digit by a group of 4 bits. The technique is less efficient than traditional binary notation. As an example, 123 represented in binary is 1111011b but the equivalent BCD representation is 000100100011b. A.3 Two's Complement Two's complement is a method for representing negative numbers in binary. The most significant bit is the sign, with 0 being positive, while 1 is negative. The range available in a single byte is therefore -128 to 127, rather than 0 to 255. A.4 Wraparound The maximum value of an unsigned byte is 255. Increasing the value causes it to wrap around to 0. Similarly, decrementing from 0 results in a value of 255. With a signed byte, the maximum positive value is 127, and incrementing beyond this will result in bit 7 being set and the value becoming -128. Around 0, the value changes smoothly between positive and negative numbers. Therefore with unsigned bytes, wraparound occurs between 255 and 0 and with signed bytes, it occurs between 127 and -128. Figure A-1. Wraparound of both unsigned (left) and signed (right) 8-bit integers. 33

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47

33
Appendix A
Arithmetic And Logic
A.1 Numbering Systems
The hexadecimal number system uses base 16 with digits 0-9 and A-F, where A represents
10 and F represents 15. The hexadecimal system is used frequently throughout this
document and any numbers written in this format will be indicated by use of the prefixes $
and 0x (used interchangeably). For example, $2F = (2 * 16) + 15 = 47.
The binary number system uses base 2 with digits 0 and 1. This system is also frequently
used and any numbers written in this format will be indicated by use of the suffix b. For
example 101111b = 32 + 8 + 4 + 2 + 1 = 47.
A.2 Binary Coded Decimal (BCD)
Binary Coded Decimal represents each digit by a group of 4 bits. The technique is less
efficient than traditional binary notation. As an example, 123 represented in binary is
1111011b but the equivalent BCD representation is 000100100011b.
A.3 Two’s Complement
Two’s complement is a method for representing negative numbers in binary. The most
significant bit is the sign, with 0 being positive, while 1 is negative. The range available in a
single byte is therefore -128 to 127, rather than 0 to 255.
A.4 Wraparound
The maximum value of an unsigned byte is 255. Increasing the value causes it to wrap
around to 0. Similarly, decrementing from 0 results in a value of 255. With a signed byte, the
maximum positive value is 127, and incrementing beyond this will result in bit 7 being set and
the value becoming -128. Around 0, the value changes smoothly between positive and
negative numbers. Therefore with unsigned bytes, wraparound occurs between 255 and 0
and with signed bytes, it occurs between 127 and -128.
Figure A-1. Wraparound of both unsigned (left) and signed (right) 8-bit integers.