File: debug.c

package info (click to toggle)
sumalibs 1.0.36-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 412 kB
  • sloc: ansic: 3,154; lex: 174; sh: 45; makefile: 26
file content (32 lines) | stat: -rwxr-xr-x 457 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/*
 * debug.c
 *
 *  Created on: 4 sept. 2012
 *      Author: coissac
 */

#include <stdlib.h>
#include <inttypes.h>
#include "debug.h"

char* int2bin(int64_t i,size_t bits)
{
    static char str[65];
    uint64_t u;

    if (bits > 64)
    	return NULL;

    str[bits] = 0;

    // type punning because signed shift is implementation-defined
    u = *(unsigned *)&i;

    for(; bits--; u >>= 1)
        str[bits] = u & 1 ? '1' : '0';

    return str;
}