I want to compose a 1-byte (unsigned char
) number, knowing its bits value.
For example, 7th and 6th are always 0
and 1
respectively, values of 5th to 3rd are stored in three other variables, and 2nd to 0th bits shall take a value stored in one variable, e.g. decimal 5
.
At first I fought I can create an array of 8 elements, to store each bit, then convert it to a decimal number using custom bin2dec
, but the problem is 1) I don't want to use additional "self-written" functions, 2) I'm not sure, how to put value 5
there (it looks like I need to dec2bin
at first).
I can solve this problem using SystemC, but I'm interested how to do it using C/C++ methods (without additional downloaded libs).