SlideShare a Scribd company logo
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 digits
0   1   2   3     4   5     6   7   8   9
Decimal Numbers
                10 digits
0   1   2   3     4   5     6   7   8   9

                base 10
4          2




* the answer to life, universe, and everything
4         2
     1         0
4 * 10 + 2 * 10
4            2
      1           0
4 * 10 + 2 * 10

 40       +   2
4              2
                          1           0
                4 * 10 + 2 * 10

                   40         +   2



               position                          position
digit * base              + ... + digit * base
8                 4              2
          2                  1           0
  8 * 10 + 4 * 10 + 2 * 10

    800       +       40         +   2



                  position                          position
digit * base                 + ... + digit * base
position                          position
digit * base              + ... + digit * base
Binary Numbers
Binary Numbers
    2 digits
Bit
A binary digit.




 0    or    1
Binary Numbers
    2 digits
     0   1

     base 2
1   0
1         0




               position                          position
digit * base              + ... + digit * base
1             0
                          1          0
                 1*2          + 0*2




               position                          position
digit * base              + ... + digit * base
1              0
                          1           0
                 1*2          + 0*2

                    2         +   0



               position                          position
digit * base              + ... + digit * base
1               1              0
         2                  1           0
   1*2       +     1*2          + 0*2

     4       +        2         +   0



                 position                          position
digit * base                + ... + digit * base
Bit
A binary digit.




 0    or    1
Nibble
  A set of 4 bits.




           0/1 0/1 0/1 0/1



Store 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 digits
0   1   2   3   4   5   6     7   8     9   A   B   C   D   E   F
Hexadecimal Numbers
                            16 digits
0   1   2   3   4   5   6     7   8     9   A   B   C   D   E   F


                            base 16
what’s interesting about Hexadecimal
numbers is that a Hex digit fits exactly
         into a Binary nibble.
1            1             1           1
     3            2             1           0
1*2      +   1*2      +    1*2      + 1*2

 8       +    4       +     2       +   1

                      15

                      F
Byte Order
Big Endian / Network Byte Order


         B3            B2   B1    B0
Most Significant Byte             Least Significant Byte
Decimal 1 stored in a 4 byte big endian word



           0           0   0          1
Most Significant Byte              Least Significant Byte
Little Endian


         B0              B1      B2      B3
Least 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 Javascript
64 bit (8 bytes) - IEEE 754 double precision floating-point
Bitwise Operators in JavaScript
The operands of all bitwise operators
are converted to signed 32-bit integers
   in big-endian order and in two's
         complement format.
Bitwise Logical Operators
&           Bitwise AND
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   1   1


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   1   0   1




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   0   1
|       Bitwise OR
0   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   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   0   1   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   1   1   0   0   0   1   0   0   0   0   0   0
^           Bitwise XOR
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   1   1


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   1   1




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   1   0   0
~           Bitwise NOT

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   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   1   0   1   0
Bitwise Shift Operators
<<              Bitwise Shift Left
                                                            9 << 2

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   0   1




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   0   0
>>              Bitwise Sign Propagating Shift Right
                                                            9 >> 2

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   0   1




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   0   1   0
>>              Bitwise Sign Propagating Shift Right
                                                        -9 >> 2

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   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   1   1   1   0   1
>>>             Bitwise Zero Fill Shift Right
                                                        -9 >>> 2

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   1   1




0   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
Blob
Binary Large Object
Bits, Bytes and Blobs
Bits, Bytes and Blobs
BlobBuilder
File Reader
ArrayBuffer
An Array Of Bytes in Memory
ArrayBufferView
A 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
HTTP
Content-Type: application/octet-stream
         or a custom header
WebSockets
Applications
Faster Calculations
Lighter Data Exchange
Speak Binary Protocols
File Manipulation
?
References
Bitwise Operators
JavaScript Numbers
File API
XmlHttpRequest Level 2
Typed Array
Canvas ImageData
Thank You


http://mrinalwadhwa.com
http://twitter.com/mrinal

More Related Content

PDF
23 gray codes
XLSX
Excel Analysis & Findings
PDF
Ip Addressing And Subnetting Teachers Book Robb Jones
PDF
Ip addressing and subnetting instructors workbook
PDF
Computer hardware michael karbo
XLSX
Excel test
XLSX
Excel slide series - fractions introduction
XLSX
Excel
23 gray codes
Excel Analysis & Findings
Ip Addressing And Subnetting Teachers Book Robb Jones
Ip addressing and subnetting instructors workbook
Computer hardware michael karbo
Excel test
Excel slide series - fractions introduction
Excel

Viewers also liked (20)

PPT
Analog and digital signals
PPT
Analogue & Digital
PPTX
Last news from New York / Buzz the Brand 2011
PPT
Reciclatge P5 Reformat
PPT
Use it or lose it : evidence based librarianship and resource management in r...
PPT
Customer connected company v2
PDF
Designing a One-Size-Fits-All University Web Template, and other Impossible B...
PDF
Let's Work Together: UCD Research, UCD Library & Altmetrics
PDF
Estonian ICT foresight
PPTX
Mg Tweek9
PPT
Dmars Part 2
PPT
Week 5 Uf 5163
PPTX
Presentation5
PPT
Estats FíSics
PPTX
OpenGovernment
PPT
Week 2 Uf 5163
PPTX
Libguides pilot at UCD Library 2013. Author: Ros Pan
PPTX
Presentation2
PPTX
Les possibilitats d’Internet aplicades a l’agricultura ecològica
PDF
From Bean Counting to Adding Value: Using Statistics to Transform Services
Analog and digital signals
Analogue & Digital
Last news from New York / Buzz the Brand 2011
Reciclatge P5 Reformat
Use it or lose it : evidence based librarianship and resource management in r...
Customer connected company v2
Designing a One-Size-Fits-All University Web Template, and other Impossible B...
Let's Work Together: UCD Research, UCD Library & Altmetrics
Estonian ICT foresight
Mg Tweek9
Dmars Part 2
Week 5 Uf 5163
Presentation5
Estats FíSics
OpenGovernment
Week 2 Uf 5163
Libguides pilot at UCD Library 2013. Author: Ros Pan
Presentation2
Les possibilitats d’Internet aplicades a l’agricultura ecològica
From Bean Counting to Adding Value: Using Statistics to Transform Services
Ad

Similar to Bits, Bytes and Blobs (20)

PDF
Lecture.1
PPTX
Lecture4 binary-numbers-logic-operations
PPT
Meghna ppt.
PPT
Sistem bilangan
PPT
Binary Conversion
PPT
Computer archi&mp
PPT
Logic Design 2009
PDF
Number system
PPT
1. basic theories of information
PPT
Ch3
PDF
4 technology
PDF
Binary reference guide csit vn1202
PPS
Binary Numbers
PPT
Cmp104 lec 2 number system
PDF
Digital and Logic Design Chapter 1 binary_systems
PDF
Number systems tutorial
PDF
Бүлэг 1
PDF
Course Intro CPSC125
PPT
Ch1 2
PPTX
Now You're Speaking My Language!
Lecture.1
Lecture4 binary-numbers-logic-operations
Meghna ppt.
Sistem bilangan
Binary Conversion
Computer archi&mp
Logic Design 2009
Number system
1. basic theories of information
Ch3
4 technology
Binary reference guide csit vn1202
Binary Numbers
Cmp104 lec 2 number system
Digital and Logic Design Chapter 1 binary_systems
Number systems tutorial
Бүлэг 1
Course Intro CPSC125
Ch1 2
Now You're Speaking My Language!
Ad

More from Mrinal Wadhwa (10)

PDF
SF IoT Meetup - Decentralized Identifiers & Verifiable Claims
PDF
Edge Computing and Machine Learning for a better Internet of Things
PDF
Considerations for a secure internet of things for cities and communities
PDF
Austin Smart City Readiness Workshop - Viability and Sustainability of IoT Sm...
PDF
Better Parking. Better Communities.
PDF
Transport Layer Security - Mrinal Wadhwa
PDF
An Introduction To Rich Internet Apllications
PDF
Custom Components In Flex 4
PDF
Flex 4 Component Lifecycle
PDF
Introduction to Rich Internet Applications, Flex, AIR
SF IoT Meetup - Decentralized Identifiers & Verifiable Claims
Edge Computing and Machine Learning for a better Internet of Things
Considerations for a secure internet of things for cities and communities
Austin Smart City Readiness Workshop - Viability and Sustainability of IoT Sm...
Better Parking. Better Communities.
Transport Layer Security - Mrinal Wadhwa
An Introduction To Rich Internet Apllications
Custom Components In Flex 4
Flex 4 Component Lifecycle
Introduction to Rich Internet Applications, Flex, AIR

Recently uploaded (20)

PPT
Teaching material agriculture food technology
PPTX
Programs and apps: productivity, graphics, security and other tools
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
Network Security Unit 5.pdf for BCA BBA.
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PPTX
Big Data Technologies - Introduction.pptx
PPTX
Cloud computing and distributed systems.
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Empathic Computing: Creating Shared Understanding
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Machine learning based COVID-19 study performance prediction
PDF
Unlocking AI with Model Context Protocol (MCP)
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Electronic commerce courselecture one. Pdf
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Teaching material agriculture food technology
Programs and apps: productivity, graphics, security and other tools
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Network Security Unit 5.pdf for BCA BBA.
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Big Data Technologies - Introduction.pptx
Cloud computing and distributed systems.
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Building Integrated photovoltaic BIPV_UPV.pdf
Empathic Computing: Creating Shared Understanding
Diabetes mellitus diagnosis method based random forest with bat algorithm
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Machine learning based COVID-19 study performance prediction
Unlocking AI with Model Context Protocol (MCP)
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Dropbox Q2 2025 Financial Results & Investor Presentation
20250228 LYD VKU AI Blended-Learning.pptx
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Electronic commerce courselecture one. Pdf
How UI/UX Design Impacts User Retention in Mobile Apps.pdf

Bits, Bytes and Blobs