I want to represent numbers as a 15 bit wide field. So, for example:
Number 15 bit wide filed representation of the number
0 000000000000000 /*15 bits*/
'a' 000000001100001 /*15 bits*/
'b' 000000001100010 /*15 bits*/
4 000000000000100 /*15 bits*/
If the number can be represented in a smaller amount of bits, 0s will precede it. I was thinking about bit fields, however when I tried doing this:
#include <stdio.h>
int main()
{
typedef struct
{
int a : 15;
}A;
A b;
b.a = 0;
printf("a is %d \n",a.b);
return 0;
}
I got this output:
0
Instead of:
000000000000000
However, I'm not talking just about printing a number (I'm not interested in %15 or anything similar). I want 0s preceding any number that can be represented in a smaller amount of bits, in any of the operations I do, not just printing.
How can I achieve this?