Imported Upstream version 1.30
[platform/upstream/x86info.git] / binary.c
1 /*
2  *  (C) 2001 Dave Jones.
3  *
4  *  Licensed under the terms of the GNU GPL License version 2.
5  *
6  *  Binary output routines.
7  */
8
9 #include <stdio.h>
10 #include "x86info.h"
11
12 void binary(unsigned int n, unsigned long value)
13 {
14         unsigned int i;
15
16         for (i = 0; i < n; i++, value<<=1)
17                 (void)putchar( (1<<(n-1) & value) ? '1' : '0' );
18         (void)putchar('\n');
19 }
20
21 void binary32(unsigned long value)
22 {
23         int i;
24
25         for (i = 0; i < 32; i++,value<<=1) {
26                 (void)putchar( (1<<31 & value) ? '1' : '0' );
27
28                 if (i == 23 || i == 15 || i == 7)
29                         (void)putchar(' ');
30         }
31         (void)putchar('\n');
32 }
33
34 void binary64(unsigned long long value)
35 {
36         binary32(value>>32);
37         printf("           ");
38         binary32(value);
39 }