Akira_Yiin

plateTest

May 30th, 2015
313
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. // plateTest.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include "stdafx.h"
  5.  
  6. #include <stdlib.h>
  7. #include <stdio.h>
  8. #include <string.h>
  9. #include <iostream>
  10.  
  11. typedef unsigned _int16 uint16_t;
  12. typedef unsigned _int32 uint32_t;
  13.  
  14. uint32_t PlateToInt(char Chars[], uint16_t Numbers) {
  15. uint16_t parts[2];
  16. for (int x = 0; x < 3; x++) Chars[x] -= 'A';
  17.  
  18. parts[0] = (Chars[0] * 26 * 26) + (Chars[1] * 26) + Chars[2];
  19. parts[1] = Numbers;
  20. return *(uint32_t *)parts;
  21. }
  22.  
  23. char *IntToPlate(const uint32_t * In) {
  24. uint16_t parts[2] = { 0, 0 };
  25.  
  26. parts[0] = ((uint16_t *)In)[0];
  27. parts[1] = ((uint16_t *)In)[1];
  28.  
  29. char *chars = (char*)(malloc(7 * sizeof(char)));
  30. memset(chars, 0, 7);
  31.  
  32. chars[2] = parts[0] % 26 + 'A'; parts[0] /= 26;
  33. chars[1] = parts[0] % 26 + 'A'; parts[0] /= 26;
  34. chars[0] = parts[0] % 26 + 'A';
  35.  
  36. char numbers[4];
  37. memset(numbers, 0, 4);
  38.  
  39. numbers[0] = parts[1] / 100 + '0';
  40. numbers[1] = (parts[1] % 100) / 10 + '0';
  41. numbers[2] = parts[1] % 10 + '0';
  42.  
  43. strcat(chars, numbers);
  44.  
  45. return chars;
  46. }
  47.  
  48.  
  49. int _tmain(int argc, _TCHAR* argv[])
  50. {
  51. char chr[3] = { 'Z', 'Z', 'Z' };
  52.  
  53. uint16_t num = 856;
  54.  
  55. uint32_t * lel = new uint32_t;
  56. *lel = PlateToInt(chr, num);
  57.  
  58. char * lol = IntToPlate(lel);
  59.  
  60. if (lel)
  61. delete lel;
  62.  
  63. printf(lol);
  64.  
  65. if (lol)
  66. free(lol);
  67.  
  68. std::cin >> num;
  69. return 0;
  70. }
Advertisement
Add Comment
Please, Sign In to add comment