xeh.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /* Copyright (C) 2016 Jeremiah Orians
  2. * This file is part of stage0.
  3. *
  4. * stage0 is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation, either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * stage0 is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with stage0. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. #include <stdlib.h>
  18. #include <unistd.h>
  19. #include <stdint.h>
  20. int main ()
  21. {
  22. char output[3] = {0};
  23. /* {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'} */
  24. char table[16] = {0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46};
  25. uint8_t c;
  26. int col = 40;
  27. int i = read(0, &c, 1);
  28. while( i > 0)
  29. {
  30. output[0] = table[c / 16];
  31. output[1] = table[c % 16];
  32. write(1, output, 2 );
  33. col = col - 2;
  34. if(0 == col)
  35. {
  36. col = 40;
  37. write(1, "\n", 1);
  38. }
  39. i = read(0, &c, 1);
  40. }
  41. write(1, "\n", 1);
  42. exit(EXIT_SUCCESS);
  43. }