Rev 1647 | Rev 1914 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | SVN | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 1647 | runge | 1 | /* |
| 2 | * |
||
| 3 | * Copyright (C) 2010 Mattias Runge |
||
| 4 | * |
||
| 5 | * This program is free software; you can redistribute it and/or modify |
||
| 6 | * it under the terms of the GNU General Public License as published by |
||
| 7 | * the Free Software Foundation; either version 2 of the License, or |
||
| 8 | * (at your option) any later version. |
||
| 9 | * |
||
| 10 | * This program is distributed in the hope that it will be useful, |
||
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
| 13 | * GNU General Public License for more details. |
||
| 14 | * |
||
| 15 | * You should have received a copy of the GNU General Public License along |
||
| 16 | * with this program; if not, write to the Free Software Foundation, Inc., |
||
| 17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
||
| 18 | * |
||
| 19 | */ |
||
| 20 | |||
| 21 | #include "common.h" |
||
| 22 | |||
| 1657 | runge | 23 | #include <iostream> |
| 24 | |||
| 1647 | runge | 25 | namespace atom { |
| 26 | namespace common { |
||
| 27 | |||
| 28 | std::string PadNumber(unsigned int number, unsigned int length) |
||
| 29 | { |
||
| 30 | std::string padded_string = boost::lexical_cast<std::string>(number); |
||
| 31 | |||
| 32 | while (padded_string.length() < length) |
||
| 33 | { |
||
| 34 | padded_string = "0" + padded_string; |
||
| 35 | } |
||
| 36 | |||
| 37 | return padded_string; |
||
| 38 | } |
||
| 39 | |||
| 40 | std::string ToHex(unsigned int value) |
||
| 41 | { |
||
| 42 | char hex_string[11]; |
||
| 43 | |||
| 44 | snprintf(hex_string, sizeof(hex_string), "0x%08X", value); |
||
| 45 | |||
| 46 | return std::string(hex_string); |
||
| 47 | |||
| 48 | } |
||
| 49 | |||
| 50 | unsigned int FromHex(std::string hex_chars) |
||
| 51 | { |
||
| 1657 | runge | 52 | return static_cast<unsigned int>(strtol(hex_chars.data(), NULL, 16)); |
| 1647 | runge | 53 | } |
| 54 | |||
| 55 | }; // namespace type |
||
| 56 | }; // namespace atom |