Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // plateTest.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- #include <stdlib.h>
- #include <stdio.h>
- #include <string.h>
- #include <iostream>
- typedef unsigned _int16 uint16_t;
- typedef unsigned _int32 uint32_t;
- uint32_t PlateToInt(char Chars[], uint16_t Numbers) {
- uint16_t parts[2];
- for (int x = 0; x < 3; x++) Chars[x] -= 'A';
- parts[0] = (Chars[0] * 26 * 26) + (Chars[1] * 26) + Chars[2];
- parts[1] = Numbers;
- return *(uint32_t *)parts;
- }
- char *IntToPlate(const uint32_t * In) {
- uint16_t parts[2] = { 0, 0 };
- parts[0] = ((uint16_t *)In)[0];
- parts[1] = ((uint16_t *)In)[1];
- char *chars = (char*)(malloc(7 * sizeof(char)));
- memset(chars, 0, 7);
- chars[2] = parts[0] % 26 + 'A'; parts[0] /= 26;
- chars[1] = parts[0] % 26 + 'A'; parts[0] /= 26;
- chars[0] = parts[0] % 26 + 'A';
- char numbers[4];
- memset(numbers, 0, 4);
- numbers[0] = parts[1] / 100 + '0';
- numbers[1] = (parts[1] % 100) / 10 + '0';
- numbers[2] = parts[1] % 10 + '0';
- strcat(chars, numbers);
- return chars;
- }
- int _tmain(int argc, _TCHAR* argv[])
- {
- char chr[3] = { 'Z', 'Z', 'Z' };
- uint16_t num = 856;
- uint32_t * lel = new uint32_t;
- *lel = PlateToInt(chr, num);
- char * lol = IntToPlate(lel);
- if (lel)
- delete lel;
- printf(lol);
- if (lol)
- free(lol);
- std::cin >> num;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment