Saturday, November 13, 2004

Bigint ( II )

Another way could be distributing the bits of the binary number over built-in types ( btw, from now on, I'll focus on C++ ), example:
We have a number 4903662431, which is 100100100010001111111001101011111in binary, and we distribute it over unsigned chars ( 8 bits most of the time ):

|00000001| |00100100| |01000111| |11110011| |01011111|
| char 1 | | char 2 | | char 3 | | char 4 | | char 5 |

See, we divide it in chunks of 8 bits going from the right to left.

Now we can easly add two numbers using less memory, and faster. The process is easy: you take the right most char from a number and the char in that in the same position from the other int and just add them together using the processor, since the result is moduled to the maximum size of the char ( in this case 256 ( 2^8 ) ) we dont have to worry about anything but the remainder. When you add in binary, if the result is bigger than 1 then you add add a 1 to the next digit, so same thing here, but how do we know when something is going to be bigger than 256? one option could be puting the result in a bigger variable, an int for example, but if we want to optimize our bigint to the maximum we'll want to use the biggest variable for adding. Another possibility is algebra, say we have 2 number a and b, and a third number c representing the maximum size, when is a + b >= c ? well easy: a+b >= c => a >= c-b, see, here we are not using numbers bigger than c.

So now that we have adding implemented, we can quickly make the multiplication and substraction, the multiplication of a times b is a summed b times so thats easy. And substraction is just like the sum but changing some minor differences.

tbc

3 Comments:

Blogger criswillis3153 said...

I read over your blog, and i found it inquisitive, you may find My Blog interesting. My blog is just about my day to day life, as a park ranger. So please Click Here To Read My Blog

December 31, 2005 10:11 PM  
Blogger shawnflynn0688 said...

I read over your blog, and i found it inquisitive, you may find My Blog interesting. So please Click Here To Read My Blog

http://pennystockinvestment.blogspot.com

January 22, 2006 3:00 PM  
Blogger travismartin2137041387 said...

Get any Desired College Degree, In less then 2 weeks.

Call this number now 24 hours a day 7 days a week (413) 208-3069

Get these Degrees NOW!!!

"BA", "BSc", "MA", "MSc", "MBA", "PHD",

Get everything within 2 weeks.
100% verifiable, this is a real deal

Act now you owe it to your future.

(413) 208-3069 call now 24 hours a day, 7 days a week.

May 6, 2006 1:55 PM  

Post a Comment

<< Home