












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
This document from carnegie mellon university's cs 213 course covers various topics related to numeric encodings, including unsigned and two's complement, programming implications, and integer representations. It also discusses the differences between signed and unsigned integers in c and the concept of sign extension.
Typology: Slides
1 / 20
This page cannot be seen from the preview
Don't miss anything!













class03.ppt CS 213 F’
C Data Type Sun, etc. Alpha long int 32 64 int 32 32 short 16 16 char 8 8
Weight 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 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 16384 0 0 1 16384 32768 0 0 1 - Sum 15213 -
x = 15213: 00111011 01101101 y = -15213: 11000100 10010011
Decimal Hex Binary UMax 65535 FF FF 11111111 11111111 TMax 32767 7F FF 01111111 11111111 TMin (^) -32768 80 00 10000000 00000000 -1 (^) -1 FF FF 11111111 11111111 0 0 00 00 00000000 00000000
short int x = 15213; unsigned short int ux = (unsigned short) x; short int y = -15213; unsigned short int uy = (unsigned short) y;
Weight -15213 50323 1 1 1 1 1 2 1 2 1 2 4 0 0 0 0 8 0 0 0 0 16 1 16 1 16 32 0 0 0 0 64 0 0 0 0 128 1 128 1 128 256 0 0 0 0 512 0 0 0 0 1024 1 1024 1 1024 2048 0 0 0 0 4096 0 0 0 0 8192 0 0 0 0 16384 1 16384 1 16384 32768 1 -32768 1 32768 Sum -15213^50323
+ 16
T2U( x )
0000
0001 0010
0011 0100
0101 0110
0111 1000
1001 1010
1011 1100
1101 1110
1111
2 w
2 w –
–2 w –1^0 2 w –
0
Identity
0 0U == unsigned -1 0 < signed -1 0U > unsigned 2147483647 -2147483648 > signed 2147483647U -2147483648 < unsigned -1 -2 > signed (unsigned) -1 -2 > unsigned 2147483647 2147483648U < unsigned 2147483647 (int) 2147483648U > signed
k copies of MSB
X • • •
w
k w
Decimal Hex Binary x 15213 3B 6D 00111011 01101101
ix 15213 00 00 C4 92 00000000 00000000 00111011 01101101
y (^) -15213 C4 93 11000100 10010011
iy (^) -15213 FF FF C4 93 11111111 11111111 11000100 10010011
short int x = 15213; int ix = (int) x; short int y = -15213; int iy = (int) y;
iux = 15213: 00000000 00000000 00111011 01101101
iuy = 50323: 00000000 00000000 11000100 10010011
uix = 15213: 00000000 00000000 00111011 01101101 uiy = 4294952083: 11111111 11111111 11000100 10010011
uuy = 4294952083: 11111111 11111111 11000100 10010011
short int x = 15213; short int y = -15213; unsigned iux = (unsigned)(unsigned short) x; unsigned iuy = (unsigned)(unsigned short) y; unsigned uix = (unsigned) (int) x; unsigned uiy = (unsigned) (int) y; unsigned uuy = y;
y
unsigned Fill 0’s
Sign Extend unsigned
iuy
uiy
(unsigned short) (unsigned)
(int) (unsigned)