CSSE 132 Mini-reading

Data Representation in 10 Minutes

Review bits and bytes, conversions among decimal, binary, and hexadecimal, and signed integers in two's complement.

Why This Matters

In CSSE 132, you will inspect memory, reason about C values, and interpret the same bits in different ways. Binary and hexadecimal make those bits easier to understand, while two's complement explains how a computer stores negative integers. These skills appear in Worksheet 02 and continue throughout the course.

Core Idea

A bit is one binary digit: either 0 or 1. Eight bits form one byte, so a byte has 28 = 256 possible bit patterns. The bits do not carry a meaning by themselves; their interpretation determines whether they represent an unsigned integer, a signed integer, an ASCII character, or something else.

One byte as an integer

0100 0001 has the unsigned decimal value 65.

The same byte as text

ASCII assigns the value 65 to A, so the same bits can represent that character in a text file such as hello.c.

Binary, decimal, and hexadecimal are all place-value systems. Count places from right to left, starting at exponent 0. Binary uses powers of 2, decimal uses powers of 10, and hexadecimal uses powers of 16.

Worked Examples

Example 1: Binary to decimal

Multiply each bit by its binary place value, then add:

101102
= 1×24 + 0×23 + 1×22 + 1×21 + 0×20
= 16 + 0 + 4 + 2 + 0
= 2210

This makes sense because the 16, 4, and 2 positions contain a 1.

Example 2: Decimal to binary

Repeatedly divide by 2 and record each remainder:

DivisionQuotientRemainder
26 ÷ 2130
13 ÷ 261
6 ÷ 230
3 ÷ 211
1 ÷ 201

Read the remainders from bottom to top: 2610 = 110102. Expanding the place values gives 16 + 8 + 2 = 26, which verifies the answer.

Example 3: Binary and hexadecimal

One hexadecimal digit represents exactly four bits. Group bits into four-bit chunks, called nibbles, starting at the right:

1100 1010 1111 11102
= C    A    F    E
= 0xCAFE

For a group shorter than four bits, add leading zeros. In C, an integer constant beginning with 0x or 0X is hexadecimal.

Example 4: Interpret a signed value

For an n-bit two's-complement value, the leftmost bit has weight -2n-1. For the 4-bit pattern 1011:

10112
= (-1×23) + (0×22) + (1×21) + (1×20)
= -8 + 0 + 2 + 1
= -510

You can verify the magnitude with the shortcut: flip 1011 to 0100, add 1 to get 0101, and read that as 5. Therefore, the original pattern represents -5.

Example 5: Build a negative value

To represent -21 in 8 bits, first write positive 21 as 0001 0101. Flip every bit and add 1:

0001 0101 → 1110 1010 → 1110 1011

So 1110 1011 is the 8-bit two's-complement representation of -21. The operation must stay within the chosen 8-bit width.

Common Mistakes

Confusing count with maximum

Eight bits give 256 unsigned values, but the largest is 255 because the values start at 0: 0 … 255.

Reading remainders forward

For repeated division, the first remainder is the rightmost bit. Read the remainders from bottom to top.

Dropping the bit width

1011 is -5 as a 4-bit signed value, but 0000 1011 is 11 as an 8-bit signed value.

Keeping overflow when negating

After flipping and adding 1, discard any carry beyond the fixed width. Keeping it changes the representation.

Quick Reference

TaskRule
Binary → decimalAdd each bit times its power-of-2 place value.
Decimal → binaryDivide by 2 repeatedly; read remainders bottom to top.
Binary ↔ hexadecimalTranslate one four-bit group per hex digit.
Negate two's complementKeep the width, flip all bits, and add 1.
n-bit unsigned range0 through 2n - 1
n-bit signed range-2n-1 through 2n-1 - 1

Hex digits: 0–9 represent values 0–9, and A–F represent values 10–15.

Check Yourself

Work these without opening the answers below. The values are different from Worksheet 02.

  1. Convert 3710 to binary.
  2. Convert 1011012 to unsigned decimal.
  3. Convert 0xB6 to binary and unsigned decimal.
  4. Interpret 1110 1011 as an 8-bit signed integer. How can you verify its magnitude?
  5. A student says the largest unsigned 8-bit value is 256 because 28 = 256. Find and correct the error.

Answers

Show the answers
  1. 1001012. The nonzero place values are 32, 4, and 1.
  2. 4510, because 32 + 8 + 4 + 1 = 45.
  3. 1011 01102 and 18210. The hex digits give 11×16 + 6.
  4. -21. Flip to 0001 0100, add 1 to get 0001 0101, and read the magnitude as 21.
  5. There are 256 possible patterns, but counting begins at 0. The range is 0 through 255, so 255 is the largest value.

Next Step

Complete Worksheet 02, then use the Practice Conversions App for more conversion practice.