USB_Host_Shield_2.0
Main Page
Related Pages
Classes
Files
File List
File Members
All
Classes
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Macros
Pages
GitHub
USB_Host_Shield_2.0
printhex.h
Go to the documentation of this file.
1
/* Copyright (C) 2011 Circuits At Home, LTD. All rights reserved.
2
3
This software may be distributed and modified under the terms of the GNU
4
General Public License version 2 (GPL2) as published by the Free Software
5
Foundation and appearing in the file GPL2.TXT included in the packaging of
6
this file. Please note that GPL2 Section 2[b] requires that all works based
7
on this software must also be made publicly available under the terms of
8
the GPL2 ("Copyleft").
9
10
Contact information
11
-------------------
12
13
Circuits At Home, LTD
14
Web : http://www.circuitsathome.com
15
e-mail : support@circuitsathome.com
16
*/
17
#if !defined(__PRINTHEX_H__)
18
#define __PRINTHEX_H__
19
20
#if defined(ARDUINO) && ARDUINO >=100
21
#include "Arduino.h"
22
#else
23
#include <WProgram.h>
24
#endif
25
26
template
<
class
T>
27
void
PrintHex
(
T
val)
28
{
29
T
mask = (((
T
)1) << (((
sizeof
(
T
) << 1) - 1) << 2));
30
31
while
(mask > 1)
32
{
33
if
(val < mask)
34
Serial.print(
"0"
);
35
36
mask >>= 4;
37
}
38
Serial.print((
T
)val, HEX);
39
}
40
41
template
<
class
T>
42
void
PrintHex2
(Print *prn,
T
val)
43
{
44
T
mask = (((
T
)1) << (((
sizeof
(
T
) << 1) - 1) << 2));
45
46
while
(mask > 1)
47
{
48
if
(val < mask)
49
prn->print(
"0"
);
50
51
mask >>= 4;
52
}
53
prn->print((
T
)val, HEX);
54
}
55
56
template
<
class
T>
57
void
PrintBin
(
T
val)
58
{
59
for
(
T
mask = (((
T
)1) << (
sizeof
(
T
) << 3)-1); mask; mask>>=1)
60
if
(val & mask)
61
Serial.print(
"1"
);
62
else
63
Serial.print(
"0"
);
64
}
65
66
#endif // __PRINTHEX_H__
Generated on Wed Jan 30 2013 21:23:57 for USB_Host_Shield_2.0 by
1.8.3.1