In the C language,
Write a program that inputs 4 hexadecimal digits as strings (example 7F), converts the string digits to a long – use strtol(input string,&ptr,base) to do the conversion. Just declare ptr as a char ptr, don’t worry about what it does. Copy each converted number [ a long] into unsigned char’s [like the variable num1 below – hint: cast a long variable into the unsigned char’s] before performing the following logical operations on them (parenthesis might help, since things should be executed from left to right): result=num1 and num2 or num 3 exclusive or num4 print out result in capital hex
#include<stdio.h>
char arr[16]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
long strtol(char string[10],char *ptr,int base){
char ch=*ptr;
long i;
for(i=0;i<16;i++){
if(arr[i]==ch){
break;
}
}
return i;
}
void print(long result){
if(result==0)
return;
print(result/16);
int val=result%16;
printf("%c",arr[val]);
return;
}
int main(){
//ios::sync_with_stdio(0);
//cin.tie(0);
//write your code here
char str[10];
long result;
long num1,num2,num3,num4;
scanf("%s",str);
num1=strtol(str,&str[0],10);
num2=strtol(str,&str[1],10);
num3=strtol(str,&str[2],10);
num4=strtol(str,&str[3],10);
result=num1 & num2 | num3 ^ num4;
print(result);
printf("\n");
return 0;
}
In the C language, Write a program that inputs 4 hexadecimal digits as strings (example 7F),...
C++ problem where should I do overflow part? in this code do not write a new code for me please /////////////////// // this program read two number from the user // and display the sum of the number #include <iostream> #include <string> using namespace std; const int MAX_DIGITS = 10; //10 digits void input_number(char num[MAX_DIGITS]); void output_number(char num[MAX_DIGITS]); void add(char num1[MAX_DIGITS], char num2[MAX_DIGITS], char result[MAX_DIGITS], int &base); int main() { // declare the array = {'0'} char num1[MAX_DIGITS] ={'0'}; char...
/*************************************************** Name: Date: Homework #7 Program name: HexUtilitySOLUTION Program description: Accepts hexadecimal numbers as input. Valid input examples: F00D, 000a, 1010, FFFF, Goodbye, BYE Enter BYE (case insensitive) to exit the program. ****************************************************/ import java.util.Scanner; public class HexUtilitySOLUTION { public static void main(String[] args) { // Maximum length of input string final byte INPUT_LENGTH = 4; String userInput = ""; // Initialize to null string Scanner input = new Scanner(System.in); // Process the inputs until BYE is entered do {...
This C++ Program consists of: operator overloading, as well as experience with managing dynamic memory allocation inside a class. Task One common limitation of programming languages is that the built-in types are limited to smaller finite ranges of storage. For instance, the built-in int type in C++ is 4 bytes in most systems today, allowing for about 4 billion different numbers. The regular int splits this range between positive and negative numbers, but even an unsigned int (assuming 4 bytes)...