Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <stdio.h>
- #include <sstream>
- using namespace std;
- int hex_to_int(unsigned char input);
- int main() {
- char hex_input[6]; // tyto tri radky jsem vygooglil :-D
- puts("Zadejte HTML kod barvy (bez hashtagu): ");
- fgets(hex_input, 6, stdin);
- int out[6];
- out[0] = hex_to_int(hex_input[0]); // tady jsem mel for cyklus, ale kdyz to nefungovalo, zkusil jsem to rucne
- cout << out[0] << endl;
- cout << hex_input[0] << endl; // tady to pokazde vypise -1
- return 0;
- }
- int hex_to_int(unsigned char input) {
- switch(input) {
- case '0': return 0;
- case '1': return 1;
- case '2': return 2;
- case '3': return 3;
- case '4': return 4;
- case '5': return 5;
- case '6': return 6;
- case '7': return 7;
- case '8': return 8;
- case '9': return 9;
- case 'a': return 10;
- case 'A': return 10;
- case 'b': return 11;
- case 'B': return 11;
- case 'c': return 12;
- case 'C': return 12;
- case 'd': return 13;
- case 'D': return 13;
- case 'e': return 14;
- case 'E': return 15;
- case 'f': return 16;
- case 'F': return 16;
- default: return -1;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement