back

Lecture 1 (01.16.21) - Binary, Hexadecimal, and Bitwise Operations

Recorded Lecture

Non-Windows Users

Why Windows is needed

If you are not on a Windows machine, you will need to gain access to one by next class, (the 23rd). Almost all the NES ROM hacking tools we will be using were made only for Windows. Unfortunately, you must use Windows if you plan on completing the Super Mario Bros. unit of this class.

Plus, having access to Windows will be extremely important moving forward at UCSB. In engineering courses, much of the software used is only for Windows. Therefore, it is best to set up a Windows environment now instead of later.

How to gain access to Windows

You can Remote Desktop into the ECI Windows machines. (Only for those with CoE Accounts)

You can use Boot Camp to install Windows on a Mac.

“What if I can’t get Windows working?”

You can always ask me for help with setup! However, if things still don’t work, you will not need Windows to complete the WAV File Parser Unit. So you could rejoin the class then.

Required Software

Be sure to have the hacking tools and a Super Mario Bros. NES ROM for next week (01.23.21).

Be sure to have the C++ environment by the WAV File Parser Unit (starts 02.06.21). If you already have one set up, you may use that for today’s exercise.Otherwise, use this online compiler just for today.

Organization

Keeping your computer organized is crucial to maximize work efficiency. Please take this class to practice organization!

Here is my personal file structure for this class. Copy it if you’d like!

Binary, Hexadecimal, and Bitwise Operations

Definitions:
In decimal: digits can be any number 0, 1, 2, 3, 4, 5, 6, 7, 8, or 9.
In binary, bits or binary digits can either be 0 or 1.
In hexadecimal, hexadecimal digits can be 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F.

Decimal Hexadecimal Binary

Computers do computations with bits, not digits. Therefore, it is important, as computer engineers, to understand binary and hexadecimal arithmetic in additon to decimal.

Common bitwise operations are:

  • & AND
  • | OR
  • ~ NOT
  • ^ XOR
  • NAND
  • NOR
  • XNOR
  • << Left Shift
  • >> Right Shift
Bitwise Operators
Truth Table

Bitwise Operations in C/C++

Using bitwise operations in C/C++ is super easy, but it important to follow these guidelines:

  • You should only use bitwise operations on unsigned numbers.*
  • You should only use the Fixed Width naming convention for declaring integers:
  • You should use hex and binary notation to declare numbers. Use the 0x prefix for hex, and the 0b prefix for binary.

* In C/C++, best practice is usually just to make ALL your variables unsigned (including chars) unless you distinctly need negative numbers. This is an important habit to get into early, so that you are used to solving bugs with unsigned integers early.