Algorithm for ASCII to Unicode Conversion
The algorithm for converting ASCII to Unicode involves mapping each ASCII character to its corresponding Unicode code point.
Let’s break down the steps of the algorithm:
- Step 1: Accept an ASCII string (inputString) as input.
- Step 2: Prepare an empty string (outputString) to store the Unicode output.
- Step 4: Iterate through each character in the input string.
- Step 5: Obtain the ASCII code of the current character (asciiCode).
- Step 6: Convert the ASCII code to the corresponding Unicode code point (unicodeCodePoint).
- Step 7: Append the Unicode code point to the output string.
- Step 8: Output the resulting Unicode string (outputString).
The algorithm for converting ASCII to Unicode involves mapping each ASCII character to its corresponding Unicode code point.
Below is the implementation for the ASCII to Unicode conversion:
C++
#include <iostream> using namespace std; int main() { char asciiCharacter = 'A' ; // Assign 'A' manually int unicodeValue = static_cast < int >(asciiCharacter); cout << "Unicode value for character 'A': " << unicodeValue << endl; return 0; } |
C
#include <stdio.h> int main() { char asciiCharacter = 'A' ; // Assign 'A' manually int unicodeValue = ( int )asciiCharacter; printf ( "Unicode value for character 'A': %d\n" , unicodeValue); return 0; } |
Java
public class Main { public static void main(String[] args) { char asciiCharacter = 'A' ; // Assign 'A' manually int unicodeValue = ( int )asciiCharacter; System.out.println( "Unicode value for character 'A': " + unicodeValue); } } |
Python
asciiCharacter = 'A' # Assign 'A' manually unicodeValue = ord (asciiCharacter) print (f "Unicode value for character 'A': {unicodeValue}" ) |
C#
using System; class Program { static void Main() { char asciiCharacter = 'A' ; // Assign 'A' manually int unicodeValue = ( int )asciiCharacter; Console.WriteLine($ "Unicode value for character 'A': {unicodeValue}" ); } } // This code is contributed by akshitaguprzj3 |
Javascript
const asciiCharacter = 'A' ; // Assign 'A' manually const unicodeValue = asciiCharacter.charCodeAt(0); console.log(`Unicode value for character 'A' : ${unicodeValue}`); |
Unicode value for character 'A': 65
Time Complexity: O(1)
Auxiliary Space: O(1)
Program to Convert ASCII to Unicode
In this article, we will learn about different character encoding techniques which are ASCII (American Standard Code for Information Interchange) and Unicode (Universal Coded Character Set), and the conversion of ASCII to Unicode.
Table of Content
- What is ASCII Characters?
- What is ASCII Table?
- What is Unicode?
- Need for ASCII to Unicode Conversion
- Algorithm for ASCII to Unicode Conversion