mirror of
https://github.com/VictorEijkhout/TheArtOfHPC_vol3_cppf08programming.git
synced 2026-01-24 22:44:48 +09:00
29 lines
763 B
C++
29 lines
763 B
C++
/****************************************************************
|
|
****
|
|
**** This file belongs with the course
|
|
**** Introduction to Scientific Programming in C++/Fortran2003
|
|
**** copyright 2017-2021 Victor Eijkhout eijkhout@tacc.utexas.edu
|
|
****
|
|
**** printbits.c : printing out bit patterns
|
|
****
|
|
****************************************************************/
|
|
|
|
#include <sstream>
|
|
|
|
//codesnippet cprintbits
|
|
std::string printBits(size_t const size, void const * const ptr)
|
|
{
|
|
std::stringstream ss;
|
|
unsigned char *b = (unsigned char*) ptr;
|
|
unsigned char byte;
|
|
int i, j;
|
|
|
|
for (i=size-1;i>=0;i--)
|
|
for (j=7;j>=0;j--) {
|
|
byte = (b[i] >> j) & 1;
|
|
ss << byte ; // originally: printf("%u", byte);
|
|
}
|
|
return ss.str();
|
|
}
|
|
//codesnippet end
|