Computer Science GCES EDEXCEL
-
Decomposition And Abstraction Edexcel2 主题
-
Algorithms Edexcel11 主题
-
Follow And Write Algorithms Edexcel
-
Introduction To Programming Concepts Edexcel
-
Basic Programming Concepts Edexcel
-
Variables Constants And Assignments Edexcel
-
Data Structures And Arrays Edexcel
-
Arithmetic Relational And Logical Operations Edexcel
-
Determine Outputs Of An Algorithm Edexcel
-
Types Of Errors Edexcel
-
Standard Sorting Algorithms Edexcel
-
Standard Searching Algorithms Edexcel
-
Algorithm Efficiency Edexcel
-
Follow And Write Algorithms Edexcel
-
Truth Tables Edexcel3 主题
-
Binary Edexcel6 主题
-
Data Representation Edexcel4 主题
-
Data Storage And Compression Edexcel2 主题
-
Hardware Edexcel5 主题
-
Software Edexcel3 主题
-
Programming Languages Edexcel2 主题
-
Networks Edexcel7 主题
-
Network Security Edexcel2 主题
-
Environmental Issues Edexcel1 主题
-
Ethical And Legal Issues Edexcel3 主题
-
Cybersecurity Edexcel2 主题
-
Develop Code Edexcel6 主题
-
Constructs Edexcel4 主题
-
Data Types And Data Structures Edexcel5 主题
-
Operators Edexcel1 主题
-
Subprograms Edexcel2 主题
Signed And Unsigned Integers Edexcel
Exam code:1CP2
Unsigned Integers
What are signed & unsigned integers?
-
Signed and unsigned integers are a data type used in computer science to represent positive and negative numbers in binary
-
A binary number can be signed or unsigned:
-
Unsigned – used to represent positive binary numbers
-
Signed – used to represent both positive and negative binary numbers
-
-
A typical 8 bit unsigned binary number can represent values from 0-255
-
A typical 8 bit signed binary number can represent values from -127 to 127
-
To represent signed integers, 1 bit is designated as the most significant bit (MSB)
-
If the MSB is 0, the number is positive
-
If the MSB is 1, the number is negative
-
-
Situations where using unsigned integers would be preferable to signed integers as non-negative value are not needed, include:
-
Indexing in arrays (typically start at 0)
-
Keeping counts or quantities (number of users, stock levels etc.)
-
Storing percentages (between 0-100%)
-
-
One method of using signed binary values to represent negative numbers is called two’s complement
Two’s Complement
What is two’s complement?
-
Two’s complement is a method of using signed binary values to represent negative numbers
-
Using two’s complement the left most bit is designated the most significant bit (MSB)
-
To represent negative numbers this bit must equal 1, turning the column value in to a negative
-
Working with 8 bits, the 128 column becomes -128
|
-128 |
64 |
32 |
16 |
8 |
4 |
2 |
1 |
|
|---|---|---|---|---|---|---|---|---|
|
1 |
1 |
1 |
1 |
1 |
1 |
1 |
1 |
= -1 |
-
In the example above to represent -1, add column values with a 1 to the MSB
-
MSB (-128)
-
Add 64 (-128+64 = -64
-
Add 32 (-64+32 = -32)
-
Add 16 (-32+16 = -16)
-
Add 8 (-16+8 = -8)
-
Add 4 (-8+4 = -4)
-
Add 2 (-4+2 = -2)
-
Add 1 (-2+1 = -1)
-
-
The two’s complement representation of -1 is 11111111
Quick two’s complement conversion
-
To represent -76
-
Write out the positive version of the number
|
128 |
64 |
32 |
16 |
8 |
4 |
2 |
1 |
|
|---|---|---|---|---|---|---|---|---|
|
0 |
1 |
0 |
0 |
1 |
1 |
0 |
0 |
= 76 |
-
Starting from the least significant bit (right most column), copy out the binary values up to and including the first 1
|
-128 |
64 |
32 |
16 |
8 |
4 |
2 |
1 |
|---|---|---|---|---|---|---|---|
|
1 |
0 |
0 |
-
For the remaining digits, invert them (0s to 1s/1s to 0s)
|
-128 |
64 |
32 |
16 |
8 |
4 |
2 |
1 |
|---|---|---|---|---|---|---|---|
|
1 |
0 |
1 |
1 |
0 |
1 |
0 |
0 |
-
-128 + 32 + 16 + 4 = -76
-
The two’s complement representation of -76 is 10110100
Responses