Subversion Repositories HomeAutomation

Rev

Rev 1684 | Rev 1939 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed

Rev 1684 Rev 1914
Line 40... Line 40...
40
std::string ToHex(unsigned int value)
40
std::string ToHex(unsigned int value)
41
{
41
{
42
    char hex_string[11];
42
    char hex_string[11];
43
   
43
   
44
    snprintf(hex_string, sizeof(hex_string), "0x%08X", value);
44
    snprintf(hex_string, sizeof(hex_string), "0x%08X", value);
-
 
45
   
-
 
46
    return std::string(hex_string);
-
 
47
   
-
 
48
}
-
 
49
 
-
 
50
std::string ToHex8bit(unsigned int value)
-
 
51
{
-
 
52
    char hex_string[3];
-
 
53
    if (value > 255) {
-
 
54
      snprintf(hex_string, sizeof(hex_string), "--");
-
 
55
    } else {
-
 
56
      snprintf(hex_string, sizeof(hex_string), "%02x", value);
-
 
57
    }
-
 
58
    return std::string(hex_string);
-
 
59
   
-
 
60
}
-
 
61
 
-
 
62
 
-
 
63
std::string ToHex4bit(unsigned int value)
-
 
64
{
-
 
65
    char hex_string[2];
-
 
66
    if (value > 15) {
-
 
67
      snprintf(hex_string, sizeof(hex_string), "-");
-
 
68
    } else {
-
 
69
      snprintf(hex_string, sizeof(hex_string), "%01x", value);
-
 
70
    }
45
   
71
   
46
    return std::string(hex_string);
72
    return std::string(hex_string);
47
   
73
   
48
}
74
}
49
 
75