# Data Representation: bits, bytes, integers

## Preview text

Data Representation: bits, bytes, integers
Yipeng Huang
Rutgers University
Feburary 11, 2021
1/26

Bits and bytes Why binary Decimal, binary, octal, and hexadecimal Bitwise operations Representing characters
Integers and basic arithmetic Representing negative and signed integers
2/26

Programming assignments
Programming assignment 1
Due date extended to: 11:59pm Monday, February 15. Take good advantage of this opportunity. Familiarity with C is a vital foundation for this class and future classes. Code review discussion during week of February 22 - February 26.
Programming assignment 2
Released later today Thursday, February 11. Due after two weeks: February 25. Same techniques in programming C. Review of graph algorithms.
3/26

Lecture plan
1. Today, Thursday, 2/11: Data representation of integers. 2. Tuesday, 2/16: Data representation of ﬂoating point numbers. 3. Thursday, 2/18: Data representation of ﬂoating point numbers.
Computer Systems: A Programmer’s Perspective Chapter 2.
4/26

Bits and bytes Why binary Decimal, binary, octal, and hexadecimal Bitwise operations Representing characters
Integers and basic arithmetic Representing negative and signed integers
5/26

Why binary
6/26

Why binary
Figure: Rahul Sarpeshkar. Analog Versus Digital: Extrapolating from Electronics to Neurobiology. 1998.
7/26

Why binary
Digital encodings
Each doubling of either precision or range only needs one additional bit.
Analog encodings
Each doubling of either precision or range needs doubling of either area or power.
8/26

Decimal 0 1 2 3 4 5 6 7

Binary 0b0000 0b0001 0b0010 0b0011 0b0100 0b0101 0b0110 0b0111

Octal 0o0 0o1 0o2 0o3 0o4 0o5 0o6 0o7

Hexadecimal 0x0 0x1 0x2 0x3 0x4 0x5 0x6 0x7

Decimal 8 9 10 11 12 13 14 15

In C, format speciﬁers for printf() and fscanf(): 1. decimal: ’%d’ 2. binary: none 3. octal: ’%o’ 4. hexadecimal: ’%x’

Binary 0b1000 0b1001 0b1010 0b1011 0b1100 0b1101 0b1110 0b1111

Octal 0o10 0o11 0o12 0o13 0o14 0o15 0o16 0o17

Hexadecimal 0x8 0x9 0xA 0xB 0xC 0xD 0xE 0xF
9/26