Show Menu
Cheatography

Signed Number Binary Representation Cheat Sheet (DRAFT) by [deleted]

This is a draft cheat sheet. It is a work in progress and is not finished yet.

Abbrev­iations and Notations

LSB: Least Signif­icant Bit (right­-most bit)
MSB: Most Signif­icant Bit (left-most bit)
SaM: Sign-a­nd-­Mag­nitude repres­ent­ation
OsC: One's Complement repres­ent­ation
TsC: Two's Complement repres­ent­ation
b
: a single bit
B_x
: set of bits repres­enting number
x
base
10
, i.e.
B_x={b_i}, i=[0,N-1]
. : in a 4-bit register,
B_x=0101
for
x=5
Unless specified otherwise, we will use throughout 8-bit (1 byte) registers to represent integers => ranges are
[0,255]
for unsigned
int
s and
[-127, 127]
for signed
int
s.

Types of Number repres­ent­ation

Mainly: SaM, OsC, TsC, excess-
K
, Base-
2
TsC most widely used. Here, only SaM, OsC and TsC are coverved.
For SaM/Os­C/TsC,
B_x
for
x>0
is the same for all repres­ent­ations (this is not the case for excess-
K
and Base-
2
)
=>
half the full range is always
B_[0, 127]=[­000­00000, 01111111]
.
-x
will then depend on choice of repres­ent­ation.
 

SaM

MSB directly represents the sign.
0
is for positive integers,
1
is for negative integers. Remaining bits are for magnitude
:
x = 43
has
B_x = 00101011
=>
x = -43
has
B_x = 10101011
2 repres­ent­ations for
0
(
00000000
(
0
) and
10000000
(
−0
))

OsC

For
x>0
,
-x
repres­ented by
B_(-x) = ~B_x
x = 43
has
B_x = 00101011
=>
x = -43
has
B_x = 11010100
2 repres­ent­ations for
0
(
B_0 = 00000000
and
B_(-0) = ~B_0 = 11111111
). In fact
B_x + B_(-x) = B_(-0)
Sometimes imposes and end-around carry/­borrow in additi­on/­sub­tra­ction (in a
4
-bit register, try
7-3
,
7+(-3)
,
(-7)+3
,
3-7
, with corres­ponding OsC bit repres­ent­ation). These do not occur in TsC arithmetic
For
x>0
with repres­ent­ation
B_x
,
B_(-x) = B_x
as per OsC definition
<=> B_(-x) = B_0 - B_x
 

References