Commit 5c48e158 authored by Benoit Rat's avatar Benoit Rat

libswitchhw: add function to display binary patterns

parent 612a766c
......@@ -9,5 +9,6 @@
void shw_udelay(uint32_t microseconds);
void *shw_malloc(size_t nbytes);
void shw_free(void *ptr);
const char *shw_2binary(uint8_t x);
#endif
......@@ -45,3 +45,21 @@ uint64_t shw_get_tics()
gettimeofday(&tv, &tz);
return (uint64_t)tv.tv_usec + (uint64_t)tv.tv_sec * 1000000ULL;
}
const char *shw_2binary(uint8_t x)
{
static char b[9];
int z;
char *p=b;
for (z=0x80; z > 0; z >>= 1)
{
*p++=(((x & z) == z) ? '1' : '0');
}
*p='\0';
return b;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment