Imported Upstream version 3.2.2
[debian/gnuradio] / usrp2 / firmware / lib / nonstdio.c
1 /* -*- c -*- */
2 /*
3  * Copyright 2007 Free Software Foundation, Inc.
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 3 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
16  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17  */
18
19 #include <nonstdio.h>
20
21 static const char hex[16] = "0123456789ABCDEF";
22
23 // %x
24 void
25 puthex4(unsigned long x)
26 {
27   putchar(hex[x & 0xf]);
28 }
29
30 // %02x
31 void 
32 puthex8(unsigned long x)
33 {
34   putchar(hex[(x >> 4) & 0xf]);
35   putchar(hex[x & 0xf]);
36 }
37
38 // %04x
39 void 
40 puthex16(unsigned long x)
41 {
42   puthex8(x >> 8);
43   puthex8(x);
44 }
45
46 // %08x
47 void 
48 puthex32(unsigned long x)
49 {
50   puthex16(x >> 16);
51   puthex16(x);
52 }
53
54 void 
55 puthex4_nl(unsigned long x)
56 {
57   puthex4(x);
58   newline();
59 }
60
61 void 
62 puthex8_nl(unsigned long x)
63 {
64   puthex8(x);
65   newline();
66 }
67
68 void 
69 puthex16_nl(unsigned long x)
70 {
71   puthex16(x);
72   newline();
73 }
74
75 void 
76 puthex32_nl(unsigned long x)
77 {
78   puthex32(x);
79   newline();
80 }