Skip to main content

Binary Codes

Binary codes 

  • Weighted codes
  • Non-weighted codes
  • Alphanumeric codes
  • Error detecting and correcting codes

Weighted Codes

Obey positional weight principle.
A specific weight is assigned to each position of the number.
Eg : Binary, BCD codes

Non-weighted Codes

Do not obey positional weight principle.
Positional weights are not assigned.
Eg : excess-3 code, Gray code

Alphanumeric Codes

Designed to represent numbers as well as alphabetic characters.
Capable of representing symbols as well as instructions.
Eg : ASCII, EBCDIC

Error Detecting and Correcting Codes

When digital data is transmitted from one system to another, an unwanted electrical disturbance called ‘noise’ may get added to it.
This can cause an ‘error’ in digital information. That means a 0 can change to 1 or 1 can change to 0.
To detect and correct such errors special type of codes capable of detecting and correcting the errors are used.
Eg : Parity code, Hamming code.

BCD(Binary Coded Decimal) Code

In this code each digit is represented by a 4-bit binary number.
The positional weights assigned to the binary digits in BCD code are 8-4-2-1 with 1 corresponding to LSB and 8 corresponding to MSB.

Conversion from decimal to BCD

The decimal digits 0 to 9 are converted into BCD, exactly in the same way as binary.
Digital to BCD
0 - 0000
1 - 0001
2 - 0010
3 - 0011
4 - 0100
5 - 0101
6 - 0110
7 - 0111
8 - 1000
9 - 1001

Invalid BCD codes

With 4 bits we can represent total sixteen numbers (0000 to 1111) but in BCD only first ten codes are used (0000 to 1001)
Therefore remaining six codes (1010 to 1111)are invalid in BCD.

Conversion of bigger decimal numbers to BCD

Express each decimal digit with its equivalent 4-bit BCD code
Eg : Convert (964)10to its equivalent BCD code.

Decimal Number →    9    6    4   
Binary Equivalent →    1001    0110    0100   

There fore (964)10= (1001 0110 0100)BCD

Hence smallest number in BCD is 0000 i.e., 0 and largest is 1001 i.e., 9
after which 10 will be expressed by combinations i.e., 0001 0000 and is known as  packed BCD

Comparison with Binary

Less efficient than binary, since conversion of a decimal number into BCD needs more bits than in binary
     Eg., (22)10= (10110)2= (0010 0010)BCD
              So BCD uses more bits than binary for the same decimal number.
              BCD arithmetic is more complicated than binary arithmetic.
BCD –decimal conversion is simpler than Binary –decimal conversion.

Advantages of BCD codes

Its similar to decimal number system.
We need to remember binary equivalents of decimal numbers 0 to 9 only.
Conversions from decimal to BCD or BCD to decimal is very simple and no calculation is needed.

Disadvantages of BCD codes

Less efficient than binary, since conversion of a decimal number into BCD needs more bits than in binary
BCD arithmetic is more complicated than binary arithmetic.

XS-3 (Excess-3)Code

Non-weighted code.
Derived from BCD code (8-4-2-1 code)words by adding (0011)2 or (3)10 to each code word.
                             Write each digit in 4-bit binary code                       + (0011)
                                Decimal                                                BCD                     XS-3
Therefore Hence smallest number in XS-3 is 0011 i.e., 0 and largest is 1100 i.e., 9
                  

Decimal | BCD | XS-3                                                       
                                                                                       1    0001    0100
 2    0010    0101                                                         3    0011    0110                                               
 4    0100    0111   
 5    0101    1000
 6    0110    1001 
 7    0111    1010 
 8    1000    1011 
 9    1001    1100                                                                           

Conversion of decimal numbers XS-3 code

Eg : Convert (964)10to its equivalent XS-3 code.

         Decimal Number →            9                   6         4   
                  XS-3 Equivalent →           1100    1001       0111       
                 
Therefore (964)10= (1100 1001 0111)XS-3
Conversion of XS-3 code to equivalent decimal numbers:
Eg : Convert (0011 1010 1100)XS-3to its equivalent decimal number.

Therefore   (1010  0011  1100)XS-3= (709)10
     

Gray Code

Non-weighted code.
It has a very special feature that only one bit will change, each time the decimal number is incremented, therefore also called unit distance code.

Binary and Gray conversions

For Gray to binary or binary to Gray conversions let’s understand rules for Ex-OR
Ex-OR is represented by symbol (    )

Conversion from Binary to Gray code

Step 1: Write MSB of given Binary number as it is.
Step 2: Ex-OR this bit with next bit of that binary number and write the result.
Step 3: Ex-OR each successive sum until LSB of that binary number is reached.
Eg : Convert (1010011)2to its equivalent Gray code.
  Therefore (1010011)2  =  (1111010)Gray
 

Conversion from Gray to Binary

Step 1: Write MSB of given gray number as it is.
Step 2: Ex-OR this bit with next bit of that binary number and write the result.
Step 3: Continue this process until LSB of that binary number is reached.
Eg: Convert (1010111)Gray to its equivalent Binary number.

ASCII-(American Standard Code for Information Interchange)

Universally accepted alphanumeric code.
Used in most computers and other electronic equipments. Most computer keyboards are standardized with ASCII.
When a key is pressed, its corresponding ASCII code is generated which goes to the computer.
Contains 128 characters and symbols.
Since 128 = 27hence we need 7 bits to write 128 characters. Therefore ASCII is a 7 bit code.
Can be represented in 8 bits by considering MSB = 0 always.
Hence we have ASCII codes from 0000 0000 to 0111 1111 in binary or from 00 to 7F in hexadecimal.
The first 32 characters are non-graphic control commands (never displayed or printed) eg., null, escape
The remaining characters are graphic symbols (can be displayed and printed). This includes alphabets (capital and small), punctuation signs and commonly used symbols.
So ASCII code consists of 94 printable characters, 32 non printable control commands and “Space” and “Delete” characters = 128 characters

EBCDIC-(Extended Binary Coded Decimal Interchange Code)

8-bit code.
Total 256 characters are possible, however all are not used.
There is no parity bit used to check error in this code set.


Comments

Trending⚡

Understanding link.click() in JavaScript

Hey! Today i am going to share with you how to use link.click() function in javascript As a JavaScript developer, you may come across the need to programmatically click a link on a web page. The link.click() method is a commonly used way to do this, and it is important to understand how it works and when to use it. What is link.click()? link.click() is a method that can be used to simulate a click on a link element in JavaScript. It is typically used when you want to trigger a link click event programmatically, rather than requiring the user to physically click the link. How to use link.click() Using link.click() is relatively straightforward. First, you need to select the link element you want to click using a DOM selector such as getElementById() or querySelector(). Then, you can call the click() method on the link element to simulate a click. Here is an example: // select the link element const myLink = document.getElementById('my-link'); // simulate a cl...

How to Create Studio Ghibli-Style AI Images on ChatGPT for Free

How to Create Studio Ghibli-Style AI Images on ChatGPT for Free AI-generated art is making waves across the internet, captivating audiences with stunning, ethereal visuals inspired by the iconic animation style of Studio Ghibli . These AI-crafted images, from dreamy landscapes to expressive characters, reflect the timeless magic of Hayao Miyazaki ’s beloved films such as Spirited Away , My Neighbor Totoro , and Howl’s Moving Castle . Thanks to recent advancements in AI technology, particularly OpenAI ’s latest ChatGPT update, users can now create their own Studio Ghibli-inspired illustrations effortlessly by entering simple text prompts. This exciting feature is transforming digital art creation and making it accessible to both professionals and beginners. In this article, we’ll guide you through creating Ghibli-style AI images using ChatGPT and explore free alternatives for users who don’t yet have access to this feature. Ghibli AI generator free Step-by-Step Guide: How to Crea...

Value Model vs Reference Model

Value Model vs Reference Model In programming languages, two different models are used for variables.  These are:  Value Model  A variable contains a value. The name of the variable gives its value.  Reference Model A variable contains (say y) refers to another variable (say x) with a value. The variable ‘y’ is used to access the value of ‘x’ indirectly.  The ‘C’ language is based on value model. However, by using pointers, we can implement the reference model. The pointer is used to access the value of a variable indirectly. Also Read Static and Dynamic Memory Allocation Memory Leak and Dangling Pointer Memory Allocation for 2D Array Dynamic Memory Allocation Pointer Constant and Constant Pointer Pointer Declarations and their Meanings Functions and Pointers Initializing Pointer to Pointer Pointer to Pointer Multiple Indirection Relationship between Array and Pointer Pointer to Array Pointer Arithmetic Types of Pointer Illustrat...

How to write programs in Bhai language

Bhai Language Bhai language is fun Programming language , with this language you can makes jokes in hindi. Bhai language written in typescript. It's very funny , easy and amazing language. Keywords of this language written in Hindi . Starting and ending of the program Start program with keyword " hi bhai " and end with " bye bhai ". It's compulsory to add this keyword before starting and end on the program. You write your programming logic inside this hi bhai and bye bhai . How to declare variables in Bhai language We use " bhai ye hai variable_name" keyword for declaring variables. In javascript we use var keyword for declaring variables but here you have to use " bhai ye hai " keyword. If you are declaring string then use " " double quotes. You can use Boolean variable like sahi and galat for true and false . How to print output in Bhai language You have to use " bol bhai " keyword for ...

ChatGPT Now Allows Free Users to Create Ghibli-Style AI Images – Here’s How

OpenAI has finally expanded its native image generation feature to free ChatGPT users, allowing them to transform images into stunning Studio Ghibli-style artwork . While the company has yet to make an official announcement, multiple tests using free ChatGPT accounts confirm that the feature is now accessible without requiring a paid subscription. Ghibli AI Images Now Available for Free Users Previously, OpenAI restricted its image generation capabilities to ChatGPT Plus, Pro, and Team users. This led free-tier users to seek alternatives like xAI’s Grok and Google’s Gemini . However, these tools often lacked the same level of detail and artistic refinement as OpenAI’s model. Now, with the rollout extending to free users, everyone can experience the magic of Ghibli-style AI transformations. How to Create Ghibli-Style AI Images with ChatGPT If you want to turn your photos into Ghibli-inspired masterpieces, follow these simple steps: Visit ChatGPT – Open the ChatGPT website or...

Quiz tells you what type of wife you want

What Type of Wife are You Looking For? Attend this quiz and know your wife expections Quiz reveals type of wife you expect, lets answer carefully... Personality Questions: 1. What type of personality are you looking for in a wife? Quiet and reserved Outgoing and social Intelligent and witty 2. What type of sense of humor are you looking for in a wife? Dry and sarcastic Witty and clever Playful and silly 3. What type of interests are you looking for in a wife? Intellectual and educational Creative and artistic Athletic and outdoorsy Values Questions: 4. What type of family values are you looking for in a wife? Traditional and conservative Open-minded and progressive Balanced and equal 5. What type of political views...