Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- char GetBinary(char hex[]);
- int main(int argc, char** argv) {
- printf("%s", GetBinary("560a"));
- }
- char GetBinary(char hex[]) {
- char bin[100] = "";
- int i = 0;
- for (i = 0; hex[i] != '\0'; i++) {
- switch (hex[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':
- case 'A':
- strcat(bin, "1010");
- break;
- case 'b':
- case 'B':
- strcat(bin, "1011");
- break;
- case 'c':
- case 'C':
- strcat(bin, "1100");
- break;
- case 'd':
- case 'D':
- strcat(bin, "1101");
- break;
- case 'e':
- case 'E':
- strcat(bin, "1110");
- break;
- case 'f':
- case 'F':
- strcat(bin, "1111");
- break;
- }
- }
- return(bin);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement