Skip to content

Instantly share code, notes, and snippets.

@jpalawaga
Created August 26, 2019 18:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jpalawaga/8d59c031d12d36e72011f7255e56f0e0 to your computer and use it in GitHub Desktop.
Save jpalawaga/8d59c031d12d36e72011f7255e56f0e0 to your computer and use it in GitHub Desktop.
Is UUID version 5 or not?
#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