Jeff Thompson | a8d7b06 | 2013-08-08 15:56:35 -0700 | [diff] [blame] | 1 | /** |
| 2 | * @author: Jeff Thompson |
| 3 | * See COPYING for copyright and distribution information. |
| 4 | */ |
| 5 | |
| 6 | #include <sstream> |
| 7 | #include "common.hpp" |
| 8 | |
| 9 | using namespace std; |
| 10 | |
| 11 | namespace ndn { |
| 12 | |
Jeff Thompson | 1656e6a | 2013-08-29 18:01:48 -0700 | [diff] [blame] | 13 | string toHex(const vector<unsigned char>& array) |
Jeff Thompson | a8d7b06 | 2013-08-08 15:56:35 -0700 | [diff] [blame] | 14 | { |
Jeff Thompson | b0948a5 | 2013-09-12 14:38:26 -0700 | [diff] [blame] | 15 | if (!&array) |
| 16 | return ""; |
| 17 | |
Jeff Thompson | a8d7b06 | 2013-08-08 15:56:35 -0700 | [diff] [blame] | 18 | ostringstream result; |
| 19 | result.flags(ios::hex | ios::uppercase); |
| 20 | for (unsigned int i = 0; i < array.size(); ++i) { |
| 21 | unsigned char x = array[i]; |
| 22 | if (x < 16) |
| 23 | result << '0'; |
| 24 | result << (unsigned int)x; |
| 25 | } |
| 26 | |
| 27 | return result.str(); |
| 28 | } |
| 29 | |
| 30 | } |
| 31 | |