Created
August 26, 2019 18:55
-
-
Save jpalawaga/8d59c031d12d36e72011f7255e56f0e0 to your computer and use it in GitHub Desktop.
Is UUID version 5 or not?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <string> | |
#include <sstream> | |
#include <algorithm> | |
using namespace std; | |
int main() { | |
cout << "Enter uuid: "; | |
string input; | |
cin >> input; | |
input.erase(std::remove(input.begin(), input.end(), '-'), input.end()); | |
string important_bits = input.substr(12,4); | |
// Convert to string (hex) to long | |
long int value; | |
istringstream iss(important_bits); | |
iss >> hex >> value; | |
int version = value & 0xf; | |
if (version == 5) { | |
cout << "UUID is version 5."; | |
} | |
else { | |
cout << "UUID is not version 5"; | |
} | |
cout << endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment