CS 2200 - PowerPoint PPT Presentation

1 / 7
About This Presentation
Title:

CS 2200

Description:

Bitwise Ops. Can only be applied to integral operands. that is, char, short, int and long ... Bitwise Quiz. Why is x = x & ~077 better than. x = x & 0177700 ... – PowerPoint PPT presentation

Number of Views:53
Avg rating:3.0/5.0
Slides: 8
Provided by: BillL161
Category:
Tags: bitwise

less

Transcript and Presenter's Notes

Title: CS 2200


1
CS 2200
  • Presentation 6a
  • Bitwise Operations

2
Questions?
3
Bitwise Ops
  • Can only be applied to integral operands
  • that is, char, short, int and long
  • (signed or unsigned)
  • Bitwise AND
  • Bitwise OR
  • Bitwise XOR
  • ltlt Shift Left
  • gtgt Shift Right
  • 1s Complement (Inversion)

4
Bitwise Quiz
  • 1 2
  • True! (1)
  • 1 2
  • 0
  • x ltlt -2 Legal?
  • No!
  • x ltlt 2 Write it another way?
  • x 4
  • What does right shifting do to signed vars?
  • depends
  • x x 077
  • Sets last six bits of x to zero!

5
Bitwise Quiz
  • Why is x x 077 better than
  • x x 0177700
  • First one is independent of word length
  • (no extra cost...evaluated at compile time)
  • What does this do?
  • (x gtgt (p1-n)) (0 ltlt n)
  • / getbits get n bits from position p /
  • unsigned getbits(unsigned x, int p, int n)
  • return (x gtgt (p1-n)) (0 ltlt n)

6
Questions?
7
(No Transcript)
Write a Comment
User Comments (0)
About PowerShow.com