I need to make a program that resolve operations between hexadecimal, where i ask for the number of hexadecimals to operate, ask for them, and then show the result.
The operations that can be done are or,and,xor(|,^,&). I made the convert part with arrays where i storage the hex number, and then convert those in binary and save it in another array but when i realize i coudnt know how many integers of hex were going to operate i coudnt figure out how to create enough arrays to storage those someone told me about i had to use pointers. Im new to that and research a bit about that still dont know how pointers can work that out...
Part of my code so far:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <float.h>
#include <proyecto.h>
#include <string.h>
int main () {
char op,bin1[31]="",bin2[31]="",hex1[100],hex2[100];
int sizeh,repeat1,repeat2,n,z,i;
printf("Write Hexadecimal:);
scanf("%s",hex1);
convert(hex1,bin1,n);
function convert:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <float.h>
#include <proyecto.h>
#include <string.h>
void convert(char hex1[],char bin1[],int n){
int i,b;
printf("\nEquivalent binary value: ");
for(i=0;i<4;i++){
switch(hex1[i]){
case '0': strcat(bin,"0000"); break;
case '1': strcat(bin,"0001"); break;
case '2': strcat(bin,"0010"); break;
case '3': strcat(bin,"0011"); break;
case '4': strcat(bin,"0100"); break;
case '5': strcat(bin,"0101"); break;
case '6': strcat(bin,"0110"); break;
case '7': strcat(bin,"0111"); break;
case '8': strcat(bin,"1000"); break;
case '9': strcat(bin,"1001"); break;
case 'A': strcat(bin,"1010"); break;
case 'B': strcat(bin,"1011"); break;
case 'C': strcat(bin,"1100"); break;
case 'D': strcat(bin,"1101"); break;
case 'E': strcat(bin,"1110"); break;
case 'F': strcat(bin,"1111"); break;
case 'a': strcat(bin,"1010"); break;
case 'b': strcat(bin,"1011"); break;
case 'c': strcat(bin,"1100"); break;
case 'd': strcat(bin,"1101"); break;
case 'e': strcat(bin,"1110"); break;
case 'f': strcat(bin,"1111"); break;
default: printf("\nInvalid hexadecimal digit %c ",hex[i]);
}
}
printf("%s",bin);
}