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