3 * Copyright 2006 Free Software Foundation, Inc.
5 * This file is part of GNU Radio.
7 * Primary Author: Michael Dickens, NCIP Lab, University of Notre Dame
9 * GNU Radio is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2, or (at your option)
14 * GNU Radio is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with GNU Radio; see the file COPYING. If not, write to
21 * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 * Boston, MA 02111-1307, USA.
28 const int g_num_bits_per_byte = 8;
30 std::string n2bs (long long number, size_t digits)
32 if (digits > (sizeof (long long) * g_num_bits_per_byte))
33 digits = sizeof (long long);
34 std::string retVal (digits, '0');
36 for (int n = --digits; n >= 0; n--) {
44 std::string n2bs (char number, size_t digits)
46 if (digits > (sizeof (char) * g_num_bits_per_byte))
47 digits = sizeof (char);
48 return n2bs ((long long) number, digits);
50 std::string n2bs (int number, size_t digits)
52 if (digits > (sizeof (int) * g_num_bits_per_byte))
53 digits = sizeof (int);
54 return n2bs ((long long) number, digits);
56 std::string n2bs (long number, size_t digits)
58 if (digits > (sizeof (long) * g_num_bits_per_byte))
59 digits = sizeof (long);
60 return n2bs ((long long) number, digits);
62 std::string n2bs (size_t number, size_t digits)
64 if (digits > (sizeof (size_t) * g_num_bits_per_byte))
65 digits = sizeof (size_t);
66 return n2bs ((long long) number, digits);
69 void cout_binary (int number, int digits)
72 std::cout << ((number >> digits) & 1);