Advertisement
Guest User

FizzBuzz C

a guest
Jan 3rd, 2015
340
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.91 KB | None | 0 0
  1. void fizzbuzz(char* buffer, int f) {
  2. uint8_t isfizz = (f % 3) == 0;
  3. uint8_t isbuzz = (f % 5) == 0;
  4. uint8_t isfizzonly = isfizz & (!isbuzz);
  5. uint8_t isbuzzonly = isbuzz & (!isfizz);
  6. uint8_t isfizzbuzz = isfizz | isbuzz;
  7.  
  8. uint32_t carry = 0;
  9. uint32_t scratch = 0;
  10.  
  11. uint8_t bit0 = (((f) >> (0))&1);
  12. uint8_t bit1 = (((f) >> (1))&1);
  13. uint8_t bit2 = (((f) >> (2))&1);
  14. uint8_t bit3 = (((f) >> (3))&1);
  15. uint8_t bit4 = (((f) >> (4))&1);
  16. uint8_t bit5 = (((f) >> (5))&1);
  17. uint8_t bit6 = (((f) >> (6))&1);
  18. uint8_t bit7 = (((f) >> (7))&1);
  19. uint8_t bit8 = (((f) >> (8))&1);
  20. uint8_t bit9 = (((f) >> (9))&1);
  21. uint8_t bit10 = (((f) >> (10))&1);
  22. uint8_t bit11 = (((f) >> (11))&1);
  23. uint8_t bit12 = (((f) >> (12))&1);
  24. uint8_t bit13 = (((f) >> (13))&1);
  25. uint8_t bit14 = (((f) >> (14))&1);
  26. uint8_t bit15 = (((f) >> (15))&1);
  27. uint8_t bit16 = (((f) >> (16))&1);
  28. uint8_t bit17 = (((f) >> (17))&1);
  29. uint8_t bit18 = (((f) >> (18))&1);
  30. uint8_t bit19 = (((f) >> (19))&1);
  31. uint8_t bit20 = (((f) >> (20))&1);
  32. uint8_t bit21 = (((f) >> (21))&1);
  33. uint8_t bit22 = (((f) >> (22))&1);
  34. uint8_t bit23 = (((f) >> (23))&1);
  35. uint8_t bit24 = (((f) >> (24))&1);
  36. uint8_t bit25 = (((f) >> (25))&1);
  37. uint8_t bit26 = (((f) >> (26))&1);
  38. scratch = (1 * bit0) + (2 * bit1) + (4 * bit2) + (8 * bit3) + (6 * bit4) + (2 * bit5) + (4 * bit6) + (8 * bit7) + (6 * bit8) + (2 * bit9) + (4 * bit10) + (8 * bit11) + (6 * bit12) + (2 * bit13) + (4 * bit14) + (8 * bit15) + (6 * bit16) + (2 * bit17) + (4 * bit18) + (8 * bit19) + (6 * bit20) + (2 * bit21) + (4 * bit22) + (8 * bit23) + (6 * bit24) + (2 * bit25) + (4 * bit26) + carry;
  39. buffer[7] = ((48 + (scratch % 10)) * (1-(isfizz | isbuzz))) + (isfizzonly * 32) + (isbuzz * 122);
  40. carry = scratch / 10;
  41. scratch = (1 * bit4) + (3 * bit5) + (6 * bit6) + (2 * bit7) + (5 * bit8) + (1 * bit9) + (2 * bit10) + (4 * bit11) + (9 * bit12) + (9 * bit13) + (8 * bit14) + (6 * bit15) + (3 * bit16) + (7 * bit17) + (4 * bit18) + (8 * bit19) + (7 * bit20) + (5 * bit21) + (1 * bit24) + (3 * bit25) + (6 * bit26) + carry;
  42. buffer[6] = ((48 + (scratch % 10)) * (1-(isfizz | isbuzz))) + (isfizzonly * 32) + (isbuzz * 122);
  43. carry = scratch / 10;
  44. scratch = (1 * bit7) + (2 * bit8) + (5 * bit9) + (1 * bit13) + (3 * bit14) + (7 * bit15) + (5 * bit16) + (1 * bit18) + (2 * bit19) + (5 * bit20) + (1 * bit21) + (3 * bit22) + (6 * bit23) + (2 * bit24) + (4 * bit25) + (8 * bit26) + carry;
  45. buffer[5] = ((48 + (scratch % 10)) * (1-(isfizz | isbuzz))) + (isfizzonly * 32) + (isbuzz * 117);
  46. carry = scratch / 10;
  47. scratch = (1 * bit10) + (2 * bit11) + (4 * bit12) + (8 * bit13) + (6 * bit14) + (2 * bit15) + (5 * bit16) + (1 * bit17) + (2 * bit18) + (4 * bit19) + (8 * bit20) + (7 * bit21) + (4 * bit22) + (8 * bit23) + (7 * bit24) + (4 * bit25) + (8 * bit26) + carry;
  48. buffer[4] = ((48 + (scratch % 10)) * (1-(isfizz | isbuzz))) + (isfizzonly * 32) + (isbuzz * 66);
  49. carry = scratch / 10;
  50. scratch = (1 * bit14) + (3 * bit15) + (6 * bit16) + (3 * bit17) + (6 * bit18) + (2 * bit19) + (4 * bit20) + (9 * bit21) + (9 * bit22) + (8 * bit23) + (7 * bit24) + (5 * bit25) + carry;
  51. buffer[3] = ((48 + (scratch % 10)) * (1-(isfizz | isbuzz))) + (isfizz * 122) + (isbuzzonly * 32);
  52. carry = scratch / 10;
  53. scratch = (1 * bit17) + (2 * bit18) + (5 * bit19) + (1 * bit22) + (3 * bit23) + (7 * bit24) + (5 * bit25) + (1 * bit26) + carry;
  54. buffer[2] = ((48 + (scratch % 10)) * (1-(isfizz | isbuzz))) + (isfizz * 122) + (isbuzzonly * 32);
  55. carry = scratch / 10;
  56. scratch = (1 * bit20) + (2 * bit21) + (4 * bit22) + (8 * bit23) + (6 * bit24) + (3 * bit25) + (7 * bit26) + carry;
  57. buffer[1] = ((48 + (scratch % 10)) * (1-(isfizz | isbuzz))) + (isfizz * 105) + (isbuzzonly * 32);
  58. carry = scratch / 10;
  59. scratch = (1 * bit24) + (3 * bit25) + (6 * bit26) + carry;
  60. buffer[0] = ((48 + (scratch % 10)) * (1-(isfizz | isbuzz))) + (isfizz * 70) + (isbuzzonly * 32);
  61. carry = scratch / 10;
  62. buffer[8] = '\0';
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement