πŸ“’
SDV503
  • SDV503
  • Command Prompt
    • Windows Command Prompt
    • Mac OS Terminal
  • GIT & GITHub
    • GitHub
    • Git
      • Git Workflow
        • Forking Workflow
  • README
    • How to write a readme.md file?
    • Write a better README.me
    • Generate a README for GitHub Repo Quickly
  • Code-comments
    • Clean Comments
    • Writing Comments in a Good way
  • Pair Coding
    • What is Pair Coding?
    • Pair Programming Experience
  • Programming?
    • What is Programming?
    • What Is A Programming Paradigm?
    • JavaScript Programming Paradigms
  • Number Systems
    • Decimal and Binary numbers
  • JavaSCript
    • Introduction To JavaScript
      • The JavaScript Engine
  • JS Call Stack
    • JavaScript call stack
    • JavaScript & Memory
      • Memory Leaks in JavaScript
    • Execution Context and Execution Stack in Javascript
      • Javascript Execution Context and Hoisting
  • JavaScript Variables
    • Introduction to JS Data Types
    • Primitive and Non-Primitive
    • Operator precedence and associativity
      • JS Operators Part One
      • JS Operators Part Two
      • JS Operators Part Three
    • Clean Code for JS Variables
  • JavaScript Scopes
    • Scope (Chain) Visualized
  • Javascript β€Šβ€”β€Šthis keyword
  • JavaScript Data Types
    • More JavaScript Data Types
  • JavaScript Expressions and Statements
  • if/else, switch and ternary operator
    • If/Else statement
  • Switch Statement
  • Ternary Operator
  • JavaScript Loops
    • Loops in JavaScript
      • Trouble With Loops
  • Objects
    • JavaScript Objects
      • Prototypal Inheritance Visualized
      • JavaScript Number Object
      • JavaScript String Object
  • Functions
    • JavaScript Function Part One
    • JavaScript Function Part Two
    • Immediately Invoked Function Expressions ~ IIFE
    • JS => Arrow Functions
    • JavaScript Callback
    • Hoisting in JavaScript
      • Hoisting Visualized
    • Recursion Functions
    • Curry and Function Composition
  • JavaScript Features
    • JSpread Operator
    • JavaScript Built-in Functions & Objects
  • Data Structures&Algorithms
    • JavaScript’s Data Types
    • Data Structures in JavaScript
      • Introduction to Big O Notation
      • Big O Notation in Javascript
      • Linked Lists
        • Linked Lists β€” 2
      • Hash Tables
      • Stack & Queue
  • TLDR
    • Single quotes (β€˜ ’) and double quotes (β€œ ”) in JavaScript
  • ES6
    • Generators and Iterators
    • Javascript Classes
    • JavaScript closures
    • JavaScript Promises & Async/Await
      • Event Loop Visualized
  • C#
    • What does C#? (C Sharp)
    • C# vs JavaScript
    • What Is The Difference Between C#, .NET, ASP.NET, Microsoft.NET, and Visual Studio?
    • What is the .NET Framework?
    • Methods and Properties of Console Class in C#
    • Datatypes in C#
    • C# Code Comments
    • The if statement
    • The switch statement
    • Loops
    • Comparison operators
    • Addition assignment operators
    • The String Interpolation Operator
    • Arrays
    • Lists
    • Dictionaries
Powered by GitBook
On this page
  • Base 2, the Basis for Binary Code
  • Decimal, the Base 10 Numbering System
  • Placeholder Value in the Decimal Numbering System
  • Binary, the Base 2 Numbering System
  • Placeholder Value in the Binary Numbering System
  • Most Significant Bit (MSB) and Least Significant Bit (LSB)
  • Decimal and Binary Equivalents
  • Steps to Convert from Decimal to Binary
  • Steps to Convert Binary to Decimal
  • Indicating the Base of a Number
  • What Other Bases Are There Apart From 2 and 10?

Was this helpful?

  1. Number Systems

Decimal and Binary numbers

PreviousJavaScript Programming ParadigmsNextIntroduction To JavaScript

Last updated 5 years ago

Was this helpful?

Base 2, the Basis for Binary Code

The base 2, or binary numbering system is the basis for all binary code and data storage in computing systems and electronic devices. This guide shows you how to convert from binary to decimal and decimal to binary.

Decimal, the Base 10 Numbering System

First let's start with decimal.

The decimal, also known as the denary or base 10 numbering system is what we use in everyday life for counting. The fact that there are ten symbols is more than likely because we have 10 fingers.

We use ten different symbols or numerals to represent the numbers from zero to nine.

Those numerals are 0, 1, 2, 3, 4, 5, 6, 7, 8 and 9

When we get to the number ten, we have no numeral to represent this value, so it is written as:

10

The idea is to use a new place holder for each power of 10 to make up any number we want.

So 134 means one hundred, 3 tens and a 4 although we just interpret and read it as the number one hundred and thirty four.

Placeholder Value in the Decimal Numbering System

Binary, the Base 2 Numbering System

In the decimal number system, we saw that ten numerals were used to represent numbers from zero to nine.

Binary only uses two numerals 0 and 1. Place holders in binary each have a value of powers of 2. So the first place has a value 20 = 1, the second place 21 = 2, the third place 22 = 4, the fourth place 23 = 8 and so on.

In binary we count 0, 1 and then since there's no numeral for two we move onto the next place holder so two is written as 10 binary. This is exactly the same as when we get to ten decimal and have to write it as 10 because there's no numeral for ten.

Placeholder Value in the Binary Numbering System

Most Significant Bit (MSB) and Least Significant Bit (LSB)

For a binary number, the most significant bit (MSB) is the digit furthermost to the left of the number and the least significant bit (LSB) is the rightmost digit.

Decimal and Binary Equivalents

Decimal

Binary

0

0

1

1

2

10

3

11

4

100

5

101

6

110

7

111

8

1000

Steps to Convert from Decimal to Binary

If you don't have a calculator to hand, you can easily convert a decimal number to binary using the remainder method. This involves dividing the number by 2 recursively until you're left with 0, while taking note of each remainder.

  1. Write down the decimal number.

  2. Divide the number by 2.

  3. Write the result underneath.

  4. Write the remainder on the right hand side. This will be 0 or 1.

  5. Divide the result of the division by 2 and again write down the remainder.

  6. Continue dividing and writing down remainders until the result of the division is 0.

  7. The most significant bit (MSB) is at the bottom of the column of remainders and the least significant bit (LSB) is at the top.

  8. Read the series of 1s and 0s on the right from the bottom up. This is the binary equivalent of the decimal number.

Steps to Convert Binary to Decimal

Converting from binary to decimal involves multiplying the value of each digit (i.e. 1 or 0) by the value of the placeholder in the number

  1. Write down the number.

  2. Starting with the LSB, multiply the digit by the value of the place holder.

  3. Continue doing this until you reach the MSB.

  4. Add the results together.

Indicating the Base of a Number

The binary number 1011011 can be written as 10110112 to explicitly indicate the base. Similarly 54 base 10 can be written 5410 Often however, the subscript is omitted to avoid excessive detail when the context is known. Usually subscripts are only included in explanatory text or notes in code to avoid confusion if several numbers with different bases are used together.

What Other Bases Are There Apart From 2 and 10?

Base 16 or hexadecimal (hex for short) is a shorthand used when programming computer systems. It uses sixteen symbols, representing 10, 11, 12, 13, 14 and 15 decimal with the letters A, B, C, D, E, and F respectively.