G
G
Grisha Nikolsky2015-12-16 16:04:47
C++ / C#
Grisha Nikolsky, 2015-12-16 16:04:47

How to correctly translate from 16CC to 2CC?

Hello. I need to enter a number in 16CC. I do it like this scanf("%x", &read);:
But now I need to determine how many bits it takes to store the number in memory.
Therefore, I need to convert the number to 2CC. How can this be done with just one function?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
M
MiiNiPaa, 2015-12-16
@VoxelGod

Why translate to determine a significant number of bits?

unsigned long long number;
std::cin >> std::hex >> number;

int bits = 0;
while(number != 0) {
    ++bits;
    number >>= 1;
}

S
Stanislav Makarov, 2015-12-16
@Nipheris

In addition to MiiNiPaa , I will say that all your numbers are already stored in binary, today's popular calc. equipment does not work with other systems. Another thing is in which SS you want to display these numbers on the screen / in a file, in general - convert them into a human-readable string. So the whole question boils down to reading help on printf arguments or on C++ stream directives.

A
abcd0x00, 2015-12-17
@abcd0x00

How to correctly translate from 16CC to 2CC?

0 - 0000
1 - 0001
2 - 0010
3 - 0011
4 - 0100
5 - 0101
6 - 0110
7 - 0111
8 - 1000
9 - 1001
A - 1010
B - 1011
C - 1100
D - 1101
E - 1110
F - 1111

1A - 0001 1010
AB - 1010 1011
FF - 1111 1111

ABFEC - 1010 1011 1111 1110 1100

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question