Using the C programming language, write a program that takes in hexadecimal characters (using the fgets() function) and return a translated string of ASCII characters. Use only BITWISE operators, not arithmetic.
#include <stdio.h>
#include <string.h>
//function to convert from hexa to decimal
int hexaToDecimal(char c)
{
int first = c;
first = first >> 4;
first = first - 3;
int second = c;
second = second & 0x0F;
int decimal = (first<<1 + first<<3) + second;
if(decimal >= 10)
decimal--;
return decimal;
}
//fuction to convert from hexa to ascii
int hexaToASCII(char firstHexa, char secondHexa)
{
int highByte = hexaToDecimal(firstHexa) << 4;
int lowByte = hexaToDecimal(secondHexa);
return highByte | lowByte;
}
int main()
{
//variable declaration
char hexa[100];// = "41";
printf("Enter hex number: ");
fgets(hexa,sizeof(hexa),stdin);
//get string length
int strLength = strlen(hexa);
//display output
printf("\nThe equivalent ASCII string is: ");
for(int i = 0; i < strLength-1; i++)
{
printf("%c", hexaToASCII(hexa[i], hexa[i+1]));
i++;
}
}
OUTPUT:
Using the C programming language, write a program that takes in hexadecimal characters (using the fgets()...
Using the C programming language, please provide a program that takes in a string of Ascii characters (using fgets()) and translate it to HEXADECIMAL using bitwise operators only, not arithmetic.
Write a C program that takes two sets of characters entered by the user and merge them character by character. Enter the first set of characters: dfn h ate Enter the second set of characters: eedtecsl Output: defend the castle Your program should include the following function: void merge(char *s3, char *s1, char *s2); The function expects s3 to point to a string containing a string that combines s1 and s2 letter by letter. The first set might be longer...
Using the programming language Java or C++, Write a function that takes an integer as input. Return true if this integer is a palindrome integer; false otherwise;
C++ programming language Write a program that contains following function: A function that receives a string of character, the function return true if the string contains letter c or C, otherwise, return false.
MIPS programming question Problem 1: Write a program that asks the user to input a string (or no more than 50 characters). Your program should then output the length of the string. The string length should be determined using a separate function strlen that will accept the address of the string and return its length. For the purposes of this exercise, the length of a string will be defined as the number of non-null and non-newline characters until either the...
C programming language: If you malloc, make sure to assert and free the data. please do not call any function you don't write yourself other than: malloc, free, assert, sizeof, scanf/printf families (eg., sprintf, fprintf & printf all OK to use) Write a function whose only argument is the input string. The function should return a new string which consists of only the upper case letters from the original string. The new string should be allocated to use the minimum...
Using C++ programming. Write a program that takes a string of input from the user and separates the string of words based on the premise that the string contains words whose first letter is uppercase. Then, display the phrase (or sentence) to a string in which the words are separated by spaces and only the first word of the phrase starts with an uppercase letter. For example, if the user enters "IAmTheTeacher", then the program would display: "I am the...
Haskell Functional Programming Language: Write a function nestedParens that takes a string argument and returns true if it is a nesting of zero or more pairs of parentheses, e.g. "((()))" should return True ; "()()" or "(()))" should return False . Use recursion for this problem. nestedParens :: String -> Bool
using C language Programming Question 1 Write a C program that takes students marks from a user, one by one until -1" is entered, which would indicate that no other marks are available, and the program terminates. For each mark the program will decide the student grade as: Fail, if mark < 60 • D. if 60<= mark <=70 • C. if 70<=mark <=80 • B. if 80c= mark <=90 • A. if 90cmark <=100 -T -- E - 15203...
IN C language Write a C program that prompts the user to enter a line of text on the keyboard then echoes the entire line. The program should continue echoing each line until the user responds to the prompt by not entering any text and hitting the return key. Your program should have two functions, writeStr andcreadLn, in addition to the main function. The text string itself should be stored in a char array in main. Both functions should operate...