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) {
- int result;
- switch(input) {
- case '0': result = 0;
- case '1': result = 1;
- case '2': result = 2;
- case '3': result = 3;
- case '4': result = 4;
- case '5': result = 5;
- case '6': result = 6;
- case '7': result = 7;
- case '8': result = 8;
- case '9': result = 9;
- case 'a': result = 10;
- case 'A': result = 10;
- case 'b': result = 11;
- case 'B': result = 11;
- case 'c': result = 12;
- case 'C': result = 12;
- case 'd': result = 13;
- case 'D': result = 13;
- case 'e': result = 14;
- case 'E': result = 15;
- case 'f': result = 16;
- case 'F': result = 16;
- default: result = -1;
- }
- return result;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement