Atlas  0.7.0
Networking protocol for the Worldforge system.
Utility.h
Go to the documentation of this file.
1 // This file may be redistributed and modified under the terms of the
2 // GNU Lesser General Public License (See COPYING for details).
3 // Copyright (C) 2000 Stefanus Du Toit, Michael Day
4 
5 // $Id$
6 
7 #ifndef ATLAS_CODECS_UTILITY_H
8 #define ATLAS_CODECS_UTILITY_H
9 
20 #include <cstdio>
21 #include <string>
22 
23 namespace Atlas {
24  namespace Codecs {
25 
27  inline std::string charToHex(char c) {
28  char hex[3];
29 #ifdef _WIN32
30  _snprintf(hex, 3, "%x", c);
31 #else
32  snprintf(hex, 3, "%x", c);
33 #endif
34  return hex;
35  }
36 
38  inline char hexToChar(const char *hex) {
39  int c;
40  if (sscanf(hex, "%x", &c) == 1) {
41  return (char) c;
42  } else {
43  return (char) 0;
44  }
45  }
46 
47  }
48 } // namespace Atlas::Codecs
49 
50 #endif // ATLAS_CODECS_UTILITY_H
std::string charToHex(char c)
Convert an ASCII char to its hexadecimal value.
Definition: Utility.h:27
char hexToChar(const char *hex)
Convert a string with a hexadecimal value (2 characters) to an ASCII char.
Definition: Utility.h:38
Definition: Bridge.h:20