2.2
Whole numbers, integers and two's complement (2.2) is a Class 9 Computer Science lesson for the Punjab boards. It walks through the idea in plain steps, then sets a short check, in English, Urdu or Roman Urdu.
Your guide: Miss HiraExplains computers with chai, cricket and your phone.
Chapter 1 of every subject is free. Unlock every chapter of this class with the full course.
Unlock full courseAlready paid? Sign in with the Google account you paid with.
Whole numbers W = {0, 1, 2, …} cannot be negative (age, number of students). They are stored as unsigned values: with n bits the largest is 2ⁿ − 1, so 255 in 1 byte, 65,535 in 2 bytes and 4,294,967,295 in 4 bytes.
Integers Z = {…, −2, −1, 0, 1, 2, …} are stored as signed integers. The most significant bit is the sign bit (1 = negative). So the range is −2ⁿ−1 to 2ⁿ−1 − 1: −128 to 127 in 1 byte, −32,768 to 32,767 in 2 bytes.
Negative values use two's complement: invert all the bits, then add 1. For −5 in 8 bits: 00000101 → 11111010 → 11111011.
Step 1 / 1
Whole numbers W = {0, 1, 2, …} cannot be negative (age, number of students). They are stored as unsigned values: with n bits the largest is 2ⁿ − 1, so 255 in 1 byte, 65,535 in 2 bytes and 4,294,967,295 in 4 bytes.
Integers Z = {…, −2, −1, 0, 1, 2, …} are stored as signed integers. The most significant bit is the sign bit (1 = negative). So the range is −2ⁿ−1 to 2ⁿ−1 − 1: −128 to 127 in 1 byte, −32,768 to 32,767 in 2 bytes.
Negative values use two's complement: invert all the bits, then add 1. For −5 in 8 bits: 00000101 → 11111010 → 11111011.
Unsigned: 0 to 2ⁿ − 1. Signed: −2ⁿ−1 to 2ⁿ−1 − 1.
Found a mistake? Tell us the lesson and the line at exciting@boringeducation.com.
No ads. Tell us what to fix.