Created
February 15, 2022 11:09
-
-
Save mancusoa74/4ac504077c19ed2dda69d523c58267aa to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<stdio.h> | |
#define DIGIT 4 | |
void dec2hex(int n){ | |
int resto = 0, carattere = 0, i = 0; | |
char hex[DIGIT] = {'0', '0', '0', '0'}; | |
printf("0x"); | |
while(n != 0){ | |
resto = n % 16; | |
if(resto<10) | |
carattere = (n % 16) + '0'; | |
else | |
carattere = (n % 16) + 'A' - 10; | |
hex[i++]=carattere; | |
n /= 16; | |
} | |
for(int i = DIGIT - 1;i >= 0;i--){ | |
printf("%c", hex[i]); | |
} | |
printf("\n"); | |
} | |
int main(){ | |
int numero; | |
printf("Inserisci un numero intero tra 0 e 65535:"); | |
scanf("%d", &numero); | |
printf("%d = ", numero); | |
dec2hex(numero); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment