Last active
October 3, 2016 20:00
-
-
Save gsauthof/a5794849d6faadf80ed4a6b2d920e3e3 to your computer and use it in GitHub Desktop.
comparison of boost hex algorithm and printf conversion specifier
This file contains hidden or 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
// re: http://stackoverflow.com/questions/28489153/how-to-portably-compute-a-sha1-hash-in-c/39833022#39833022 | |
#include <boost/uuid/sha1.hpp> | |
#include <boost/detail/endian.hpp> | |
#include <boost/algorithm/hex.hpp> | |
#include <boost/range/iterator_range_core.hpp> | |
#include <boost/endian/conversion.hpp> | |
#include <iostream> | |
#include <stdio.h> | |
using namespace std; | |
int main(int argc, char **argv) | |
{ | |
unsigned i = 1; | |
unsigned j = boost::endian::native_to_big(i); | |
boost::algorithm::hex(boost::make_iterator_range( | |
reinterpret_cast<const char*>(&j), | |
reinterpret_cast<const char*>(&j+1)), | |
ostream_iterator<char>(cout)); cout << '\n'; | |
printf("%08x\n", i); | |
printf("%08x\n", j); | |
return 0; | |
} | |
/* Output: | |
00000001 | |
00000001 | |
01000000 | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment