Bits, Bytes and Blobs
Upcoming SlideShare
Loading in...5
×
 

Bits, Bytes and Blobs

on

  • 7,252 views

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

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

Statistics

Views

Total Views
7,252
Views on SlideShare
0
Embed Views
7,972

Actions

Likes
2
Downloads
42
Comments
1

13 Embeds 7,972

http://weblog.mrinalwadhwa.com 3952
http://weblog.mrinalwadhwa.com 3952
http://paper.li 27
http://feeds.feedburner.com 15
http://localhost 9
http://www.linkedin.com 5
http://abtasty.com 4
http://a0.twimg.com 2
http://webcache.googleusercontent.com 2
http://10.1.254.17:15871 1
http://www.hanrss.com 1
http://cc.bingj.com 1
http://eventifier.co 1
More...

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
  • buena
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Bits, Bytes and Blobs Bits, Bytes and Blobs Presentation Transcript

  • Bits, Bytes and Blobs Binary programming in Javascript Mrinal Wadhwa www.mrinalwadhwa.com
  • Abstraction
  • Why think in binary ?
  • Number Systems
  • Decimal Numbers
  • Decimal Numbers 10 digits
  • Decimal Numbers 10 digits0 1 2 3 4 5 6 7 8 9
  • Decimal Numbers 10 digits0 1 2 3 4 5 6 7 8 9 base 10
  • 4 2* the answer to life, universe, and everything
  • 4 2 1 04 * 10 + 2 * 10
  • 4 2 1 04 * 10 + 2 * 10 40 + 2
  • 4 2 1 0 4 * 10 + 2 * 10 40 + 2 position positiondigit * base + ... + digit * base
  • 8 4 2 2 1 0 8 * 10 + 4 * 10 + 2 * 10 800 + 40 + 2 position positiondigit * base + ... + digit * base
  • position positiondigit * base + ... + digit * base
  • Binary Numbers
  • Binary Numbers 2 digits
  • BitA binary digit. 0 or 1
  • Binary Numbers 2 digits 0 1 base 2
  • 1 0
  • 1 0 position positiondigit * base + ... + digit * base
  • 1 0 1 0 1*2 + 0*2 position positiondigit * base + ... + digit * base
  • 1 0 1 0 1*2 + 0*2 2 + 0 position positiondigit * base + ... + digit * base
  • 1 1 0 2 1 0 1*2 + 1*2 + 0*2 4 + 2 + 0 position positiondigit * base + ... + digit * base
  • BitA binary digit. 0 or 1
  • Nibble A set of 4 bits. 0/1 0/1 0/1 0/1Store values 0 to 15
  • 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
  • Hexadecimal Numbers
  • Hexadecimal Numbers 16 digits
  • Hexadecimal Numbers 16 digits0 1 2 3 4 5 6 7 8 9 A B C D E F
  • Hexadecimal Numbers 16 digits0 1 2 3 4 5 6 7 8 9 A B C D E F base 16
  • what’s interesting about Hexadecimalnumbers is that a Hex digit fits exactly into a Binary nibble.
  • 1 1 1 1 3 2 1 01*2 + 1*2 + 1*2 + 1*2 8 + 4 + 2 + 1 15 F
  • Byte Order
  • Big Endian / Network Byte Order B3 B2 B1 B0Most Significant Byte Least Significant Byte
  • Decimal 1 stored in a 4 byte big endian word 0 0 0 1Most Significant Byte Least Significant Byte
  • Little Endian B0 B1 B2 B3Least Significant Byte Most Significant Byte
  • Decimal 1 stored in a 4 byte little endian word 1 0 0 0 Least Significant Byte Most Significant Byte
  • Numbers in Javascript64 bit (8 bytes) - IEEE 754 double precision floating-point
  • Bitwise Operators in JavaScript
  • The operands of all bitwise operatorsare converted to signed 32-bit integers in big-endian order and in twos complement format.
  • Bitwise Logical Operators
  • & 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
  • | 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
  • ^ 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
  • ~ 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
  • Bitwise Shift Operators
  • << 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
  • >> 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
  • >> 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
  • >>> 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
  • Encoding
  • Text Formats
  • Binary Formats
  • Fixed Width Data Types
  • Variable Width Data Types
  • Storage in JavaScript
  • String String.charCodeAt(index)String.fromCharCode(n1, ... nn)
  • Array of Numbers
  • BlobBinary Large Object
  • BlobBuilder
  • File Reader
  • ArrayBufferAn Array Of Bytes in Memory
  • ArrayBufferViewA view of a part of the ArrayBuffer
  • TypedArrays ArrayBufferViews where each element is of a certain type -Int8Array, Uint8Array, Int16Array, Uint16Array, Int32Array, Uint32Array, Float32Array, Float64Array
  • TypedArrays
  • DataView
  • ImageData
  • Transport
  • HTTPContent-Type: application/octet-stream or a custom header
  • WebSockets
  • Applications
  • Faster Calculations
  • Lighter Data Exchange
  • Speak Binary Protocols
  • File Manipulation
  • ?
  • ReferencesBitwise OperatorsJavaScript NumbersFile APIXmlHttpRequest Level 2Typed ArrayCanvas ImageData
  • Thank Youhttp://mrinalwadhwa.comhttp://twitter.com/mrinal