Lecture Slides on Computer System Design unit 1


char 1 1 1 short


Download 293.03 Kb.
bet4/4
Sana23.03.2023
Hajmi293.03 Kb.
#1287852
1   2   3   4
Bog'liq
SOC2040 SP WEEK 3 LECTURE SLIDES ON DATA REPRESENTATION SPRING 2023

char

1

1

1

short

2

2

2

int

4

4

4

long

4

8

8

float

4

4

4

double

8

8

8

long double





10/16

pointer

4

8

8

DATA SIZES (in Bytes)

SOC 2040 SYSTEM PROGRAMMING

WEEK 3 LECTURE

BIT LEVEL MANIPULATIONS

Bit Level Manipulations

  • Boolean Algebra - Developed by George Boole in 19th Century

Bitwise and &
  • A&B = 1 when both A=1 and B=1

Bitwise Or |
  • A|B = 1 when either A=1 or B=1

Bitwise not ~
  • ~A = 1 when A=0

Bitwise Exclusive-Or (Xor) ^
  • A^B = 1 when either A=1 or B=1, but not both

General Boolean Algebras

  • Operate on Bit Vectors
  • All of the Properties of Boolean Algebra Apply

01101001
& 01010101
01000001
01101001
| 01010101
01111101
01101001
^ 01010101
1100
~ 01010101
10101010
01000001
01111101
00111100
10101010

Example: Representing & Manipulating Sets

  • Representation
    • Width w bit vector represents subsets of {0, …, w–1}
    • xj = 1 if j ∈ X
      • 01101001 { 0, 3, 5, 6 }
      • 76543210
      • 01010101 { 0, 2, 4, 6 }
      • 76543210
  • Operations
    • & Intersection 01000001 { 0, 6 }
    • | Union 01111101 { 0, 2, 3, 4, 5, 6 }
    • ^ Symmetric difference 00111100 { 2, 3, 4, 5 }
    • ~ Complement 10101010 { 1, 3, 5, 7 }
    • of 01010101


What is X^X ?

Bit-Level Operations in C

  • Operations &, |, ~, ^ Available in C
    • Apply to any “integral” data type
      • long, int, short, char, unsigned
    • View arguments as bit vectors
    • Arguments applied bit-wise
  • Examples (Char data type)
  • ~0x41 ➙ 0xBE (HEX)

    ~010000012 ➙ 101111102 (BINARY)

    ~0x00 ➙ 0xFF (HEX)

    ~000000002 ➙ 111111112 (BINARY)

    0x69 & 0x55 ➙ 0x41 (HEX)

    011010012 & 010101012 ➙ 010000012 (BINARY)

    0x69 | 0x55 ➙ 0x7D (HEX)

    011010012 | 010101012 ➙ 011111012 (BINARY)

Contrast: Logic Operations in C

  • Contrast to Logical Operators
    • &&, ||, !
      • View 0 as “False”
      • Anything nonzero as “True”
      • Always return 0 or 1
      • Early termination
  • Examples (char data type)
    • !0x41 ➙ 0x00
    • !0x00 ➙ 0x01
    • !!0x41 ➙ 0x01
    • 0x69 && 0x55 ➙ 0x01
    • 0x69 || 0x55 ➙ 0x01
    • p && *p (avoids null pointer access)

Contrast: Logic Operations in C

  • Contrast to Logical Operators
    • &&, ||, !
      • View 0 as “False”
      • Anything nonzero as “True”
      • Always return 0 or 1
      • Early termination
  • Examples (char data type)
    • !0x41 ➙ 0x00
    • !0x00 ➙ 0x01
    • !!0x41 ➙ 0x01
    • 0x69 && 0x55 ➙ 0x01
    • 0x69 || 0x55 ➙ 0x01
    • p && *p (avoids null pointer access)

Watch out for && vs. & (and || vs. |)…
one of the more common oopsies in C programming

Contrast: Logic Operations in C

Given x = 0x4C and y = 0xB3, Compute the following showing all steps (i) x && y = (ii) x & y =

  • x && y

  • = 0x4C && 0xB3
    = 0x01 && 0x01
    = true && true
    = true
    = 0x01
    = 1
    Where true = 0x01 = 1
    false = 0x00 = 0

(ii) x & y
= 0x4C & 0xB3
= 01001100 & 10110011
= 00000000
= false
= 0x00
= 0
Where true = 0x01 = 1
false = 0x00 = 0
01001100
& 10110011
00000000

SOC 2040 SYSTEM PROGRAMMING

END OF

WEEK 3 LECTURE 2

DATA REPRESENTATION

WISH YOU ALL THE BEST


SOC 2040 SYSTEM PROGRAMMING
Reading Assignments
Chapter 2 of Text Book
  • Computer Systems : A Programmer’s Perspective

  • - Randal E. Bryant and David R. O’Hallaron
    3rd Edition, Global Edition Prentice Hall 2016
    ISBN 10:1-292-10176-8

INHA UNIVERSITY TASHKENT SPRING SEMESTER 2023 SOC 2040 SYSTEM PROGRAMMING CREDITS/HOURS PER WEEK : 3/3 COURSE TYPE : TECHNICAL CORE SEQUENCE INSTRUCTOR DR. A. R. NASEER HEAD & PROFESSOR OF COMPUTER SCIENCE & ENGG


Download 293.03 Kb.

Do'stlaringiz bilan baham:
1   2   3   4




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling