util: add printHex() overload that takes a uint64_t

And AsHex helper class.

Change-Id: If6fb6edea258ab281b5ea9cc30deffd2d8994dc5
Refs: #3006
diff --git a/src/encoding/nfd-constants.cpp b/src/encoding/nfd-constants.cpp
index c1c8060..2b9f8ff 100644
--- a/src/encoding/nfd-constants.cpp
+++ b/src/encoding/nfd-constants.cpp
@@ -20,9 +20,10 @@
  */
 
 #include "nfd-constants.hpp"
+#include "util/string-helper.hpp"
 
-#include <iostream>
 #include <map>
+#include <ostream>
 
 namespace ndn {
 namespace nfd {
@@ -137,20 +138,17 @@
     std::string token;
     std::tie(bit, token) = pair;
 
-    if ((routeFlags & bit) == 0) {
-      continue;
+    if ((routeFlags & bit) != 0) {
+      printToken(token);
+      routeFlags = static_cast<RouteFlags>(routeFlags & ~bit);
     }
-
-    printToken(token);
-    routeFlags = static_cast<RouteFlags>(routeFlags & ~bit);
   }
 
-  if (routeFlags != 0) {
-    printToken("0x");
-    std::ios_base::fmtflags oldFmt = os.flags();
-    os << std::hex << std::nouppercase
-       << static_cast<uint64_t>(routeFlags);
-    os.flags(oldFmt);
+  if (routeFlags != ROUTE_FLAGS_NONE) {
+    if (!isFirst) {
+      os << '|';
+    }
+    os << AsHex{routeFlags};
   }
 
   return os;