Bits, Bytes and Blobs

8,444 views
8,091 views

Published on

A presentation introducing binary programming in JavaScript, That I presented at jsFoo Bangalore - October 1, 2011

Published in: Technology, Business
1 Comment
2 Likes
Statistics
Notes
No Downloads
Views
Total views
8,444
On SlideShare
0
From Embeds
0
Number of Embeds
4,013
Actions
Shares
0
Downloads
43
Comments
1
Likes
2
Embeds 0
No embeds

No notes for slide

Bits, Bytes and Blobs

  1. Bits, Bytes and Blobs Binary programming in Javascript Mrinal Wadhwa www.mrinalwadhwa.com
  2. Abstraction
  3. Why think in binary ?
  4. Number Systems
  5. Decimal Numbers
  6. Decimal Numbers 10 digits
  7. Decimal Numbers 10 digits0 1 2 3 4 5 6 7 8 9
  8. Decimal Numbers 10 digits0 1 2 3 4 5 6 7 8 9 base 10
  9. 4 2* the answer to life, universe, and everything
  10. 4 2 1 04 * 10 + 2 * 10
  11. 4 2 1 04 * 10 + 2 * 10 40 + 2
  12. 4 2 1 0 4 * 10 + 2 * 10 40 + 2 position positiondigit * base + ... + digit * base
  13. 8 4 2 2 1 0 8 * 10 + 4 * 10 + 2 * 10 800 + 40 + 2 position positiondigit * base + ... + digit * base
  14. position positiondigit * base + ... + digit * base
  15. Binary Numbers
  16. Binary Numbers 2 digits
  17. BitA binary digit. 0 or 1
  18. Binary Numbers 2 digits 0 1 base 2
  19. 1 0
  20. 1 0 position positiondigit * base + ... + digit * base
  21. 1 0 1 0 1*2 + 0*2 position positiondigit * base + ... + digit * base
  22. 1 0 1 0 1*2 + 0*2 2 + 0 position positiondigit * base + ... + digit * base
  23. 1 1 0 2 1 0 1*2 + 1*2 + 0*2 4 + 2 + 0 position positiondigit * base + ... + digit * base
  24. BitA binary digit. 0 or 1
  25. Nibble A set of 4 bits. 0/1 0/1 0/1 0/1Store values 0 to 15
  26. Byte A set of 8 bits.0/1 0/1 0/1 0/1 0/1 0/1 0/1 0/1 Store values 0 to 255
  27. Hexadecimal Numbers
  28. Hexadecimal Numbers 16 digits
  29. Hexadecimal Numbers 16 digits0 1 2 3 4 5 6 7 8 9 A B C D E F
  30. Hexadecimal Numbers 16 digits0 1 2 3 4 5 6 7 8 9 A B C D E F base 16
  31. what’s interesting about Hexadecimalnumbers is that a Hex digit fits exactly into a Binary nibble.
  32. 1 1 1 1 3 2 1 01*2 + 1*2 + 1*2 + 1*2 8 + 4 + 2 + 1 15 F
  33. Byte Order
  34. Big Endian / Network Byte Order B3 B2 B1 B0Most Significant Byte Least Significant Byte
  35. Decimal 1 stored in a 4 byte big endian word 0 0 0 1Most Significant Byte Least Significant Byte
  36. Little Endian B0 B1 B2 B3Least Significant Byte Most Significant Byte
  37. Decimal 1 stored in a 4 byte little endian word 1 0 0 0 Least Significant Byte Most Significant Byte
  38. Numbers in Javascript64 bit (8 bytes) - IEEE 754 double precision floating-point
  39. Bitwise Operators in JavaScript
  40. The operands of all bitwise operatorsare converted to signed 32-bit integers in big-endian order and in twos complement format.
  41. Bitwise Logical Operators
  42. & Bitwise AND0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 10 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 10 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 1
  43. | Bitwise OR0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 1 0 0 0 0 0 00 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 1 0 0 0 1 0 0 0 0 0 00 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 0 0 0 1 0 0 0 0 0 0
  44. ^ Bitwise XOR0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 1 10 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 1 10 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0
  45. ~ Bitwise NOT0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 11 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 0
  46. Bitwise Shift Operators
  47. << Bitwise Shift Left 9 << 20 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 10 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 1 0 0
  48. >> Bitwise Sign Propagating Shift Right 9 >> 20 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 10 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0
  49. >> Bitwise Sign Propagating Shift Right -9 >> 21 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 11 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1
  50. >>> Bitwise Zero Fill Shift Right -9 >>> 21 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 10 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1
  51. Encoding
  52. Text Formats
  53. Binary Formats
  54. Fixed Width Data Types
  55. Variable Width Data Types
  56. Storage in JavaScript
  57. String String.charCodeAt(index)String.fromCharCode(n1, ... nn)
  58. Array of Numbers
  59. BlobBinary Large Object
  60. BlobBuilder
  61. File Reader
  62. ArrayBufferAn Array Of Bytes in Memory
  63. ArrayBufferViewA view of a part of the ArrayBuffer
  64. TypedArrays ArrayBufferViews where each element is of a certain type -Int8Array, Uint8Array, Int16Array, Uint16Array, Int32Array, Uint32Array, Float32Array, Float64Array
  65. TypedArrays
  66. DataView
  67. ImageData
  68. Transport
  69. HTTPContent-Type: application/octet-stream or a custom header
  70. WebSockets
  71. Applications
  72. Faster Calculations
  73. Lighter Data Exchange
  74. Speak Binary Protocols
  75. File Manipulation
  76. ?
  77. ReferencesBitwise OperatorsJavaScript NumbersFile APIXmlHttpRequest Level 2Typed ArrayCanvas ImageData
  78. Thank Youhttp://mrinalwadhwa.comhttp://twitter.com/mrinal

×