Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- int myatoi(char achar);
- unsigned char BitShift(unsigned char x);
- int main()
- {
- unsigned char val;
- unsigned char par;
- val = myatoi('a');
- printf("Val: %un", val);
- par = BitShift(val);
- printf("Par: %un", par);
- }
- unsigned char BitShift(unsigned char x)
- {
- x ^= x >> 4;
- x ^= x >> 2;
- x ^= x >> 1;
- return (x & 0x1);
- }
- int myatoi(char achar)
- {
- int value;
- switch(achar)
- {
- case '0':
- value = 0;
- break;
- case '1':
- value = 1;
- break;
- case '2':
- value = 2;
- break;
- case '3':
- value = 3;
- break;
- case '4':
- value = 4;
- break;
- case '5':
- value = 5;
- break;
- case '6':
- value = 6;
- break;
- case '7':
- value = 7;
- break;
- case '8':
- value = 8;
- break;
- case '9':
- value = 9;
- break;
- case 'a':
- case 'A':
- value = 10;
- break;
- case 'b':
- case 'B':
- value = 11;
- break;
- case 'c':
- case 'C':
- value = 12;
- break;
- case 'd':
- case 'D':
- value = 13;
- break;
- case 'e':
- case 'E':
- value = 14;
- break;
- case 'f':
- case 'F':
- value = 15;
- break;
- default:
- value = 0;
- } // end switch
- return value;
- }
- Val = 10
- x ^= x >> 4; gives x = 10
- x ^= x >> 2; gives x = 8
- x ^= x >> 1; gives x = 12
- Par = 0
Add Comment
Please, Sign In to add comment