Tuesday, April 16, 2024
HomeAcademicEverything about ASCII in C

Everything about ASCII in C

American Standard Code for Information Interchange(ASCII) is a standard of character encoding for electronic communication. ASCII codes are universally used as a way to represent text in computers, networking equipment, and other various types of devices like IoTs and HHDs, etc. 

Usually, ASCII codes are written in 8 bits binary notations in case of binary arithmetics to represent different characters including upper case and lowercase alphabets as well as special symbols.

To print the ASCII Code in C Programming language, you can use different ways.

  • Take a character from the user and print ASCII of it.
  • Print all ASCII values
  • Print ASCII values between some range.

1. Get Character from the user and print ASCII Value of that character

#include<stdio.h>
void main()
{
    int e;
    char character;
    clrscr();
    printf("\n Enter a character of your choice: ");
    scanf("%c",&character);
    e=character;
    printf("\n The ASCII value of the character you've entered is : %d",e);
    getch();
}

One thing you should always consider while playing with ASCII is that the ASCII values of all the characters will be between 0 and 255. That’s why we need to use a loop starting at 0 and iterating up to 255 to print all characters in range 0 to 255.

For example, the following is the ASCII Table that shows ASCII of different characters and their equivalent values in a different number systems.

Image Source: https://www.kindpng.com/

Below is a table for non-printable ASCII Characters.

Image Source: https://www.fpds.gov/

2. To print ASCII of all characters and symbols

#include <stdio.h>
void main()
{
  int e;
  for(e = 0; e <= 255; i++){
    printf("The ASCII value of %c = %d\n", e, e);
   }
  getch();	
}


At the point when value of e is 65, it will print
The ASCII value of A = 65

3. To Print ASCII of characters in the range, one shall go with the following idea.

#include <stdio.h>
void main()
{
  int e;
  for(e = 65; e <= 90; i++){
    printf("The ASCII value of %c = %d\n", e, e);
   }
  getch();	
}

To print UPPER CASE english alphabets.
#include <stdio.h>
void main()
{
  int e;
  for(e = 97; e <= 122; i++){
    printf("The ASCII value of %c = %d\n", e, e);
   }
  getch();	
}



To print lower case english alphabets.

Thanks for being with me up to this point. Please share if you’ve found this article interesting.

datasagarhttp://www.DataSagar.com
The author of this blog post is a technology fellow, an IT entrepreneur, and Educator in Kathmandu Nepal. With his keen interest in Data Science and Business Intelligence, he writes on random topics occasionally in the DataSagar blog.
RELATED ARTICLES
- Advertisment -

Most Popular