From 2f7767bc9be88e2130044fad236c4c050df127c5 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Fri, 15 Mar 2013 12:25:13 -0700 Subject: [PATCH] add helper method to SharedUtil to print bits in char --- shared/src/SharedUtil.cpp | 10 +++++++++- shared/src/SharedUtil.h | 1 + 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/shared/src/SharedUtil.cpp b/shared/src/SharedUtil.cpp index 4515eafe40..13b8219343 100644 --- a/shared/src/SharedUtil.cpp +++ b/shared/src/SharedUtil.cpp @@ -8,6 +8,7 @@ #include "SharedUtil.h" #include +#include double usecTimestamp(timeval *time) { return (time->tv_sec * 1000000.0 + time->tv_usec); @@ -19,7 +20,14 @@ double usecTimestampNow() { return (now.tv_sec * 1000000.0 + now.tv_usec); } - float randFloat () { return (rand()%10000)/10000.f; +} + +void outputBits(char byte) { + printf("%d: ", byte); + for (int i = 0; i < 8; i++) { + printf("%d", byte >> (7 - i) & 1); + } + printf("\n"); } \ No newline at end of file diff --git a/shared/src/SharedUtil.h b/shared/src/SharedUtil.h index d5525ffdb9..2410e0e2cb 100644 --- a/shared/src/SharedUtil.h +++ b/shared/src/SharedUtil.h @@ -15,5 +15,6 @@ double usecTimestamp(timeval *time); double usecTimestampNow(); float randFloat(); +void outputBits(char); #endif /* defined(__hifi__SharedUtil__) */