























































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Representing information as bits ... Apply to any “integral” data type ... So, how are the bytes within a multi-byte word ordered in memory? □ Conventions.
Typology: Lecture notes
1 / 63
This page cannot be seen from the preview
Don't miss anything!
























































Carnegie Mellon
Introduction
to
Computer
Systems
p^
y
nd 2
and
rd Lectures,
Jan
and
Jan
Instructors: Todd
Mowry
Anthony
Rowe
Carnegie Mellon
Representation: unsigned and signedRepresentation:
unsigned
and
signed
Conversion,
casting
Expanding,
truncating
Additi
ti^
lti li
ti^
hifti
Addition,
negation,
multiplication,
shifting
Summary
Carnegie Mellon
Binary 00000000
to 11111111
Binary
to 2
2
Decimal:
10
to
10
Hexadecimal
16
to
16
0
0
0000
1
1
0001
2
2
0010
3
3
0011
4
4
0100
^
Base
number
representation
^
Use
characters
to
and
to
^
Write
16
in
as
4
4
0100
5
5
0101
6
6
0110
7
7
0111
8
8
1000
6
8
8
1000
9
9
1001
A^
10
1010
B^
11
1011
C^
12
1100
C^
12
1100
D^
13
1101
E^
14
1110
F^
15
1111
Carnegie Mellon
C Data Type
Typical 32-bit
Intel IA
x86-
char
1
1
1
short
2
2
2
int
4
4
4
long
4
4
8
long long
8
8
8
float
4
4
4
double
8
8
8
long double
8
10/
10/
i t
4
4
8
pointer
4
4
8
Carnegie Mellon
Algebraic representation of logic
Algebraic
representation
of
logic
^
Encode
“True”
as
and
“False”
as
^
when
both
and
^
when
either
or
when
^
when
either
or
but
not
both
Carnegie Mellon
Operations applied bitwise
Operations
applied
bitwise
Carnegie Mellon
Apply to any “integral” data type
Apply
to
any
“integral”
data
type
^
long, int, short, char, unsigned
View
arguments
as
bit
vectors
Arguments
applied
bit
‐wise
~0x
0
xBE
0
0
^
~
2
10111110
2
~0x
0xFF
^
~
2
11111111
2
00000000
2
11111111
2
0x69 & 0x
0x
^
01101001
& 01010101 2
2
01000001
2
0x69 | 0x
0x7D
0x
| 0x
0x7D
^
01101001
| 01010101 2
01111101
2
Carnegie Mellon
^
View
as
“False”
^
Anything
nonzero
as
“True”
^
Always
return
or
^
Early
termination
!0x
0x
!0x
0x
!!0x
0x
!!0x
0x
0x69 && 0x
0x
0x69 || 0x
0x
||
p && *p
(avoids
null
pointer
access)
Carnegie Mellon
Shift bit
vector
x
left
y
positions
01100010
Argument
x
Shift
bit
‐vector
x
left
y
positions
away
extra
bits
on
left
^
Fill
with
0
’s
on
right
00010
000
<< 3
00
011000
Log.
>> 2
00
011000
Arith
>> 2
00010
000
00010
000
00
011000 00
011000 00
011000 00
011000
Shift
bit
‐vector
x
right
y
positions
^
Throw away extra bits on right
00
011000
Arith
.^ >>
2
10100010
Argument
x
00
011000 00
011000
^
Throw
away
extra
bits
on
right
Logical
shift
^
Fill
with
0
’s
on left
g
00010
000
<< 3
00
101000
Log.
>> 2
00010
000
00
101000 00010
000
00
101000
Arithmetic
shift
^
Replicate
most
significant
bit
on left
11
101000
Arith.
>> 2
11
101000 11
101000
Shift
amount
or
word
size
Carnegie Mellon
Representation: unsigned and signedRepresentation:
unsigned
and
signed
Conversion,
casting
Expanding,
truncating
Additi
ti^
lti li
ti^
hifti
Addition,
negation,
multiplication,
shifting
Summary
Carnegie Mellon
x =
15213: 00111011 01101101
y =
-15213: 11000100 10010011
Weight
15213
‐^15213
Weight
15213
‐^15213
1
1
1
1
1
2
0
0
1
2
4
1
4
0
0
8
1
8
0
0
16
0
0
1
16
32
1
32
0
0
64
1
64
0
0
64
1
64
0
0
128
0
0
1
128
256
1
256
0
0
512
1
512
0
0
1024
0
0
1
1024
2048
1
2048
0
0
4096
1
4096
0
0
8192
1
8192
0
0
8192
1
8192
0
0
16384
0
0
1
16384
‐^32768
0
0
1
‐^32768
Sum
15213
‐^15213
Carnegie Mellon
^
Unsigned
Values
UMin
^
Two’s
Complement
Values
TMin
w –
1
000…
UMax
w 2
111…
TMin
100…
TMax
w 2
011
1
011…
^
Other
Values
Minus
111…
Decimal
Hex
Binary
Values
for
y
UMax
65535
FF
FF
11111111
11111111
TMax
32767
7 F
FF
01111111
11111111
TMin
-
80
00
10000000
00000000
1
1
FF
FF
11111111
11111111
- -
FF
FF
11111111
11111111
0
0
00
00
00000000
00000000
Carnegie Mellon
Same
encodings
for
nonnegative
l
X^
B2T(
X )
B2U(
X )
0000
0
0001
1
0 1
values
Every
bit
pattern
represents
0001
1
0010
2
0011
3
0100
4
1 2 3 4
unique
integer
value
Each
representable integer
has
unique
bit
encoding
0100
4
0101
5
0110
6
0111
7
4 5 6 7
x )
x )
Bit
tt
f^
i^
d
8
9
10
100010011010
^
Bit
pattern
for
unsigned
integer
x )
x )
11
12
13
2
14
1011110011011110
^
Bit
pattern
for
two’s
comp
integer
14
15
11101111
Carnegie Mellon
Representation: unsigned and signedRepresentation:
unsigned
and
signed
Conversion,
casting
Expanding,
truncating
Additi
ti^
lti li
ti^
hifti
Addition,
negation,
multiplication,
shifting
Summary