Guest User

Untitled

a guest
Feb 18th, 2019
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. #include <stdio.h>
  2. int myatoi(char achar);
  3. unsigned char BitShift(unsigned char x);
  4.  
  5. int main()
  6. {
  7. unsigned char val;
  8. unsigned char par;
  9.  
  10. val = myatoi('a');
  11. printf("Val: %un", val);
  12. par = BitShift(val);
  13. printf("Par: %un", par);
  14. }
  15.  
  16. unsigned char BitShift(unsigned char x)
  17. {
  18. x ^= x >> 4;
  19. x ^= x >> 2;
  20. x ^= x >> 1;
  21. return (x & 0x1);
  22. }
  23.  
  24. int myatoi(char achar)
  25. {
  26. int value;
  27.  
  28. switch(achar)
  29. {
  30. case '0':
  31. value = 0;
  32. break;
  33. case '1':
  34. value = 1;
  35. break;
  36. case '2':
  37. value = 2;
  38. break;
  39. case '3':
  40. value = 3;
  41. break;
  42. case '4':
  43. value = 4;
  44. break;
  45. case '5':
  46. value = 5;
  47. break;
  48. case '6':
  49. value = 6;
  50. break;
  51. case '7':
  52. value = 7;
  53. break;
  54. case '8':
  55. value = 8;
  56. break;
  57. case '9':
  58. value = 9;
  59. break;
  60. case 'a':
  61. case 'A':
  62. value = 10;
  63. break;
  64. case 'b':
  65. case 'B':
  66. value = 11;
  67. break;
  68. case 'c':
  69. case 'C':
  70. value = 12;
  71. break;
  72. case 'd':
  73. case 'D':
  74. value = 13;
  75. break;
  76. case 'e':
  77. case 'E':
  78. value = 14;
  79. break;
  80. case 'f':
  81. case 'F':
  82. value = 15;
  83. break;
  84. default:
  85. value = 0;
  86. } // end switch
  87.  
  88. return value;
  89.  
  90. }
  91.  
  92. Val = 10
  93. x ^= x >> 4; gives x = 10
  94. x ^= x >> 2; gives x = 8
  95. x ^= x >> 1; gives x = 12
  96. Par = 0
Add Comment
Please, Sign In to add comment