473,471 Members | 1,905 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Multiplication algorithm and code for base 256 ?

Hello,

type
Tbig = array of byte;

vAddTable : array[0..255,0..255] of array[0..1] of byte;
// [0] = value
// [1] = transport/carry

vMulTable : array[0..255,0..255] of array[0..1] of byte;
// [0] = value
// [1] = value

procedure BigMul( const A : Tbig; const B : Tbig; var C : Tbig );

The mission is to:

1. Multiply A and B and store result in C.
2. Use lookup tables only.
3. Use bytes and words only. (8 bit and 16 bit)
4. No native/cpu arithmetic is allowed.

Can you implement it ?

Code can be in Delphi/Pascal or C/C++ with slightly modified prototypes,
example:

void BigMul( char A[], int LengthA, char B[], int LengthB );

Bye,
Skybuck.
Mar 11 '07 #1
11 5204
In article <et**********@news4.zwoll1.ov.home.nl>,
Skybuck Flying <sp**@hotmail.comwrote:
[....]
>procedure BigMul( const A : Tbig; const B : Tbig; var C : Tbig );

The mission is to:

1. Multiply A and B and store result in C.
2. Use lookup tables only.
3. Use bytes and words only. (8 bit and 16 bit)
4. No native/cpu arithmetic is allowed.
Since the indexing of an array involves an add operation this last
requirement forbids the use of table unless you allow the address of the
table to be forced and permit operations such as ORing and combining of
bits.

>
Can you implement it ?
Are we permitted a test for zero? Can we use as many tables as we want?

Your prototype below doesn't include the "C" argument you suggested as the
place to put the results. Clear up these problems and the code is very
easy.
>
Code can be in Delphi/Pascal or C/C++ with slightly modified prototypes,
example:

void BigMul( char A[], int LengthA, char B[], int LengthB );

Bye,
Skybuck.


--
--
ke******@rahul.net forging knowledge

Mar 11 '07 #2

"Ken Smith" <ke******@green.rahul.netwrote in message
news:et**********@blue.rahul.net...
In article <et**********@news4.zwoll1.ov.home.nl>,
Skybuck Flying <sp**@hotmail.comwrote:
[....]
>>procedure BigMul( const A : Tbig; const B : Tbig; var C : Tbig );

The mission is to:

1. Multiply A and B and store result in C.
2. Use lookup tables only.
3. Use bytes and words only. (8 bit and 16 bit)
4. No native/cpu arithmetic is allowed.

Since the indexing of an array involves an add operation this last
requirement forbids the use of table unless you allow the address of the
table to be forced and permit operations such as ORing and combining of
bits.
Arithmetic on indexes is allowed.
>>Can you implement it ?

Are we permitted a test for zero?
Yes.
Can we use as many tables as we want?
One table for addition.

One table for multiplication.

What more tables would you want ?
Your prototype below doesn't include the "C" argument you suggested as the
place to put the results. Clear up these problems and the code is very
easy.
My mistake I shall correct the mistake:
>>Code can be in Delphi/Pascal or C/C++ with slightly modified prototypes,
example:
void BigMul( char A[], int LengthA, char B[], int LengthB );
void BigMul( unsigned char A[], unsigned int LengthA, unsigned char B[],
unsigned int LengthB, unsigned char *C[], unsigned int *LengthC )

Allocate example inside routine:

*C = (unsigned char *) malloc(100);

Access example:

(*C)[5] = 200;

*LengthC = 100;

Call example:

unsigned char[100];
// etc
unsigned char *C;

BigMul( A, LengthA, B, LengthB, &C, &LengthC );

Free example outside routine:

Free(C);

That should help you along...

Bye,
Skybuck.
Mar 11 '07 #3
In article <et**********@news4.zwoll1.ov.home.nl>,
Skybuck Flying <sp**@hotmail.comwrote:
>
"Ken Smith" <ke******@green.rahul.netwrote in message
news:et**********@blue.rahul.net...
>In article <et**********@news4.zwoll1.ov.home.nl>,
Skybuck Flying <sp**@hotmail.comwrote:
[....]
>>>procedure BigMul( const A : Tbig; const B : Tbig; var C : Tbig );

The mission is to:

1. Multiply A and B and store result in C.
2. Use lookup tables only.
3. Use bytes and words only. (8 bit and 16 bit)
4. No native/cpu arithmetic is allowed.

Since the indexing of an array involves an add operation this last
requirement forbids the use of table unless you allow the address of the
table to be forced and permit operations such as ORing and combining of
bits.

Arithmetic on indexes is allowed.
>>>Can you implement it ?

Are we permitted a test for zero?

Yes.
>Can we use as many tables as we want?

One table for addition.

One table for multiplication.
One for the multiply is wastefully large. With one for adding, perhaps
one for subtracting and one with (X^2)/2 is enough to do it.

The subtacting one is not needed if the logical compliment is also
allowed.

>
What more tables would you want ?
>Your prototype below doesn't include the "C" argument you suggested as the
place to put the results. Clear up these problems and the code is very
easy.

My mistake I shall correct the mistake:
>>>Code can be in Delphi/Pascal or C/C++ with slightly modified prototypes,
example:
void BigMul( char A[], int LengthA, char B[], int LengthB );

void BigMul( unsigned char A[], unsigned int LengthA, unsigned char B[],
unsigned int LengthB, unsigned char *C[], unsigned int *LengthC )

Allocate example inside routine:

*C = (unsigned char *) malloc(100);

Access example:

(*C)[5] = 200;

*LengthC = 100;

Call example:

unsigned char[100];
// etc
unsigned char *C;

BigMul( A, LengthA, B, LengthB, &C, &LengthC );

Free example outside routine:

Free(C);

That should help you along...

Bye,
Skybuck.


--
--
ke******@rahul.net forging knowledge

Mar 11 '07 #4
>>Can we use as many tables as we want?
>>
One table for addition.

One table for multiplication.

One for the multiply is wastefully large. With one for adding, perhaps
one for subtracting and one with (X^2)/2 is enough to do it.

The subtacting one is not needed if the logical compliment is also
allowed.
All kinds of lookup tables are allowed to look up operations based on digits
only.

As soon as you try to lookup multiple digits which are combined a number
it's not allowed.

So substracing table is allowed.

So (X^2)/2 table is allowed, as long as X is in range: 0..255

Bye,
Skybuck.
Mar 11 '07 #5
In article <et**********@news5.zwoll1.ov.home.nl>,
Skybuck Flying <sp**@hotmail.comwrote:
>>>Can we use as many tables as we want?

One table for addition.

One table for multiplication.

One for the multiply is wastefully large. With one for adding, perhaps
one for subtracting and one with (X^2)/2 is enough to do it.

The subtacting one is not needed if the logical compliment is also
allowed.

All kinds of lookup tables are allowed to look up operations based on digits
only.
This makes writing the program so trival, I'm not interested in the
question.
--
--
ke******@rahul.net forging knowledge

Mar 11 '07 #6

"Ken Smith" <ke******@green.rahul.netwrote in message
news:et**********@blue.rahul.net...
In article <et**********@news5.zwoll1.ov.home.nl>,
Skybuck Flying <sp**@hotmail.comwrote:
>>>>Can we use as many tables as we want?

One table for addition.

One table for multiplication.

One for the multiply is wastefully large. With one for adding, perhaps
one for subtracting and one with (X^2)/2 is enough to do it.

The subtacting one is not needed if the logical compliment is also
allowed.

All kinds of lookup tables are allowed to look up operations based on
digits
only.

This makes writing the program so trival, I'm not interested in the
question.
I spent a whole day trying to solve the problem.

I finally succceeded by using subroutines that solved my problem.

I am definetly interested in seeing your implementation...

Also it would be interesting to benchmark all methods to see which
look-up-table version is faster.

Bye,
Skybuck.

Mar 12 '07 #7
Ken Smith wrote:
Skybuck Flying <sp**@hotmail.comwrote:
.... snip ...
>
>All kinds of lookup tables are allowed to look up operations
based on digits only.

This makes writing the program so trival, I'm not interested in
the question.
Please don't feed the troll.

--
Chuck F (cbfalconer at maineline dot net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net>

--
Posted via a free Usenet account from http://www.teranews.com

Mar 12 '07 #8
In article <et**********@news4.zwoll1.ov.home.nl>,
Skybuck Flying <sp**@hotmail.comwrote:
>
"Ken Smith" <ke******@green.rahul.netwrote in message
news:et**********@blue.rahul.net...
>In article <et**********@news5.zwoll1.ov.home.nl>,
Skybuck Flying <sp**@hotmail.comwrote:
>>>>>Can we use as many tables as we want?
>
>One table for addition.
>
>One table for multiplication.

One for the multiply is wastefully large. With one for adding, perhaps
one for subtracting and one with (X^2)/2 is enough to do it.

The subtacting one is not needed if the logical compliment is also
allowed.

All kinds of lookup tables are allowed to look up operations based on
digits
only.

This makes writing the program so trival, I'm not interested in the
question.

I spent a whole day trying to solve the problem.
A whole day on just this! I don't think so.

>I finally succceeded by using subroutines that solved my problem.
In C++ you could make a class where the operators produce the normal
results by means of look ups.
--
--
ke******@rahul.net forging knowledge

Mar 12 '07 #9

"Ken Smith" <ke******@green.rahul.netwrote in message
news:et**********@blue.rahul.net...
In article <et**********@news4.zwoll1.ov.home.nl>,
Skybuck Flying <sp**@hotmail.comwrote:
>>
"Ken Smith" <ke******@green.rahul.netwrote in message
news:et**********@blue.rahul.net...
>>In article <et**********@news5.zwoll1.ov.home.nl>,
Skybuck Flying <sp**@hotmail.comwrote:
>>Can we use as many tables as we want?
>>
>>One table for addition.
>>
>>One table for multiplication.
>
One for the multiply is wastefully large. With one for adding,
perhaps
one for subtracting and one with (X^2)/2 is enough to do it.
>
The subtacting one is not needed if the logical compliment is also
allowed.

All kinds of lookup tables are allowed to look up operations based on
digits
only.

This makes writing the program so trival, I'm not interested in the
question.

I spent a whole day trying to solve the problem.

A whole day on just this! I don't think so.
Yes, I was having problems with the transport/carry.

It's best to determine the transport/carry/overflow at the same time and
store it for later use.

Example:

C := First digit of (C + A);

Transport := Second digit of (C + A);

^^ problem, C already updated, transport result incorrect. (Using the tables
directly in this way would cause this problem).

I also searched the net for some inspiration and finally decided to work out
a clean example by hand to determine patterns in the output and to see if it
action.

And finally by using a subroutine which solves the problem above,
programming it was a piece of cake ;)

Bye,
Skybuck.
Mar 12 '07 #10
BTW, the old IBM 1620 computer had no hardware adder or multiplier--
it depended on a couple of addition and multiplication tables in low
memory. This was core memory so that eliminated some of the cant-get-
there-from-here problems.


Mar 12 '07 #11
On Mar 12, 3:18 am, CBFalconer <cbfalco...@yahoo.comwrote:
Ken Smith wrote:
SkybuckFlying <s...@hotmail.comwrote:

... snip ...
All kinds of lookup tables are allowed to look up operations
based on digits only.
This makes writing the program so trival, I'm not interested in
the question.

Please don't feed the troll.

--
Chuck F (cbfalconer at maineline dot net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net>

--
Posted via a free Usenet account fromhttp://www.teranews.com
Starving creatures is mean !

You are a mean guy Chuck !

I give trolls lot's of love, attention and food until they have had
enough of it.

Then they just go away...

Bye,
Skybuck.

Mar 13 '07 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Michael Bader | last post by:
Hi, I'm currently working on a matrix multiplication code (matrix times matrix), and have come along some interesting/confusing results concerning the running time of the (apparently) same...
17
by: Christopher Dyken | last post by:
Hi group, I'm trying to implement two routines to handle 32x32-bits and 64x64-bits signed integer multiplication on a 32 bits machine in C. It easy to find descriptions of non-signed...
11
by: mjdeesh_hi | last post by:
How can we perfom multiplication programatically without using + or * operator. Can any one help out in this one. Jagadeesh.
1
emaghero
by: emaghero | last post by:
Does anybody know an algorithm for the fast multiplication of three n-x-n symmetric matrices? I have an algorithm, which I'm not too pleased with, that does the job. Does anybody know a faster...
7
by: VijaKhara | last post by:
Hi all, Is there any method which can implememt the matrix multiplication faster than using the formula as we often do by hand? I am writing the following code and my matrice: one is 3x40000 and...
5
by: challenge | last post by:
i need help to start writting the C program Karatusuba Multiplication using the GMP library . I read alot about the Karatusuba Multiplication algorithm but i don't know how to start implement this...
9
by: helPlease | last post by:
hello !! Can anybody provide me an algorithm or C code for long integer multiplication.It's urgent.
2
by: helPlease | last post by:
I want to multiply two very long integers (say of 20 digits).I am storing them in character array.Then what mechanism should i follow to mutiply two such numbers.If anybody has any suggestions...
1
by: Sozos | last post by:
Hi guys. I have a problem with writing the base case for the following matrix multiplication function I have implemented. Please help. #define index(i,j,power) (((i)<<(power))+(j)) void...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.