1 / 100

Bit Wizardry

Bit Wizardry. 1. the art of a binary wizard 10. a bit of sorcery 11. bit by bit, it looks like magic 100. a great ability in using bits. Who do we think we are?. We. Dhruv Matani (tall guy) Ashwin Jain (thin guy) Shilp Gupta (fat guy). We. Programmers

aglaia
Télécharger la présentation

Bit Wizardry

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Bit Wizardry • 1. the art of a binary wizard • 10. a bit of sorcery • 11. bit by bit, it looks like magic • 100. a great ability in using bits

  2. Who do we think we are?

  3. We • Dhruv Matani (tall guy) • Ashwin Jain (thin guy) • Shilp Gupta (fat guy)

  4. We • Programmers • Software Developers, Directi • Bit Wizards

  5. Who do we think you are?

  6. You • Programmers • Wish to become Bit Wizards

  7. Bit Wizards • Better programmers • Bits are cool!

  8. Why?

  9. Why? • Bits are simple • zero • one

  10. Why? • Bit operations are simple • and • or • not

  11. Why? • 2n is common • Tower of Hanoi • Dynamic Programming • Set cover

  12. Why Tower of Hanoi? • 3n states • Optimal sequence contains • (2n - 1) moves • General case?

  13. Why DP? • Weighted Matching • TSP • Domino Tiling • The list goes on..

  14. Why Set Cover? • Statement • Given ‘n’ items, you are given the cost of covering, each subset of items. Which mutually exclusive subsets to select, such that the union selects all items and the total cost of cover is minimal among all covers.

  15. Why 2n? • n-bits to mask them all,n-bits to find them,n-bits compress them alland in an array bind them

  16. What the cuss was that?

  17. Compress space • Premise • byte - smallest unit of “point-able” memory • byte = 8 bits • Conclusion • Waste not, want not

  18. Faster lookup? • Masks are numbers • Numbers make lightening fast indexes • Think, array!

  19. Are you convinced? • Say yes.

  20. Pay attention! • You too @ashwin + @dhruv!

  21. Rules • If in doubt / distress / disbelief / discomfort / disorientation or difficulty, ask question

  22. Caution • Parenthesize your bit operations • If using Turbo C++ / Borland C++, use long int instead of int

  23. 001 • Bit by Bit

  24. bit • A unit of information. • 0 or 1

  25. byte • 1 byte = 8 bits • char (g++)

  26. short int • 1 short int = 16 bits • short int (g++) • int (turbo c++)

  27. int • 1 int = 4 bytes = 32 bits • int (g++) • long int (turbo c++)

  28. long long int • 1 long long int = 64 bits • long long int (g++) • __int64 (visual c++)

  29. and • conjunction • truth table

  30. or • disjunction • truth table

  31. not • negation • truth table

  32. xor • exclusive or / toggle • truth table

  33. bitwise operators • x & y • x | y • ~x • x^y

  34. shift operators • >> • <<

  35. Do it yourself. • wake up, open your computer, try them

  36. Print the input in binary using bitwise operators.

  37. Sieve the primes < 1024 using an array of 32 ints only!

  38. Solution • SET(n) A[n >> 5] |= (1 << (n & 31)) • UNSET(n) A[n>>5] &= ~(1 << (n&31))

  39. 010 • Things you should know

  40. 2n • 1 followed by n 0’s

  41. 2n - 1 • 1 repeated n times

  42. -1 • all 1’s

  43. << • multiply by power of 2

  44. >> • divide by power of 2

  45. & (2n - 1) • remainder on division by 2n

  46. x & 1 • is the number even or odd?

  47. x & (x - 1) • is x a power of 2? • x &= (x-1) removes the least significant set bit! • can you think of immediate uses?

  48. x & (x + 1) • is the binary expansion of x all 1’s?

  49. x & (-x) • smallest power of 2 in the binary expansion of x

  50. x & (-x) • -x = ~x + 1 • 2’s complement notation • Understand this very carefully!

More Related