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
23namespace Atlas {
24 namespace Codecs {
25
27 inline std::string charToHex(char c) {
28 char hex[3];
29 snprintf(hex, 3, "%x", c);
30 return hex;
31 }
32
34 inline char hexToChar(const char *hex) {
35 int c;
36 if (sscanf(hex, "%x", &c) == 1) {
37 return (char) c;
38 } else {
39 return (char) 0;
40 }
41 }
42
43 }
44} // namespace Atlas::Codecs
45
46#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:34
Definition: Bridge.h:20