Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

Help 

As an int appears in the console? C++

Read carefully before answering the following!

Computers "talk" only binary language then each variable, etc. and two to a set of 1's and 0 place in ram.

My question is' simple, as you can convert a list of bits in a decimal number without using types like int, double, etc.?

The conversion from decimal to binary number and a 'very simple if you work directly with the bits of the variable:

Code
for (int i = 0; i <sizeof (unsigned) * 8; i ++)
        {
            bits [i] = (v >> i) & 1;
        } // The code works if and only if the length of the array of bits and 'higher (or equal to) 32

Note: In the above code bits and a bitset.

Regarding the conversion to decimal a possible solution would be to use an algorithm of the type:

Code
for(int i=0;i<32;i++)
{
myInt += bits[i] * pow(2,i);
}

However, such a solution requires that the number is not bigger than an int, a long or long long (note: the example works only with int), otherwise an overflow error.

Now suppose we have an array of 512 bits or more 'items. This is the number that you could not calculate with the aforementioned method because 'greatly exceeds the capacity of all numeric types, that algorithm could be used to make the conversion?

Initially I thought I could use the shakes which then go on to build a class that performs this work, however, it gives me the idea of ​​being a further complication of the work with even the pitiful performance.


Possibly Related Threads...
Thread / Author Replies Views Last Post
[Assembly] by gamg7May 17, 2016 09:09 PM 1 220 May 17, 2016 09:09 PM
Last Post: brownclown
[Help] by Ðr1psNov 1, 2015 01:55 PM 10 193 Nov 1, 2015 01:55 PM
Last Post: Ðr1ps
[Assembly] by c0mputer-fr0dOct 20, 2012 08:34 PM 10 364 Oct 20, 2012 08:34 PM
Last Post: c0mputer-fr0d