本文介绍了基数为256的乘法算法和代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,


类型

Tbig =字节数组;


vAddTable:array [0。 .255,0..255]数组[0..1]的字节;

// [0] =值

// [1] =运输/随身携带


vMulTable:数组[0..1]的数组[0..255,0..255];

// [0 ] = value

// [1] =值


程序BigMul(const A:Tbig; const B:Tbig; var C:Tbig);


任务是:


1.将A和B相乘并将结果存储在C.

2。仅使用查找表。

3.仅使用字节和单词。 (8位和16位)

4.不允许使用native / cpu算法。


你能实现吗?


代码可以是Delphi / Pascal或C / C ++,稍加修改原型,

例如:


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


再见,

Skybuck。

解决方案



由于数组的索引涉及添加操作,因此最后

要求禁止使用表,除非您允许
表被强制并允许操作,例如ORing和

位的组合。



我们是否允许零测试?我们可以使用尽可能多的表吗?


下面的原型并不包括C表。你建议作为

放置结果的地方。清除这些问题,代码非常简单。
$ blockquote class =post_quotes>
>
代码可以是Delphi / Pascal或C / C ++略微修改原型,


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

再见,

Skybuck。



-

-
锻造知识




由于数组的索引涉及添加操作,因此最后

要求禁止使用表,除非您允许
表被强制并允许操作,例如ORing和

位的组合。



允许对索引进行算术运算。



我们是否允许零测试?



是。



一张表用于添加。


一张表用于乘法。


你还想要什么表?



我的错误我将更正错误:



void BigMul(unsigned char A [],unsigned int LengthA,unsigned char B [],

unsigned int LengthB ,unsigned char * C [],unsigned int * LengthC)


在例程中分配示例:


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


访问示例:


(* C)[5] = 200;


* LengthC = 100;


电话示例:


unsigned char [100];

//等

unsigned char * C;


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


免费示例外例:


免费(C);


这应该可以帮助你... 。


再见,

Skybuck。



由于数组的索引涉及添加操作,因此最后的要求禁止使用表,除非您允许强制使用表的地址并且允许ORing和
位组合等操作。


允许对索引进行算术运算。


我们是否允许零测试?


是的。


一个表用于添加。

一个用于乘法的表。



乘法的一个是浪费大。有一个用于添加,也许

一个用于减去,一个用(X ^ 2)/ 2就足够了。


提交一个不是如果逻辑恭维也允许

,则需要。


我的错误我将更正错误:


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

在例程中分配示例:

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

访问示例:

(* C)[5] = 200;

* LengthC = 100;

呼叫示例:

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

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

免费的例外情况:

免费(C);

这应该可以帮助你...

再见,

Skybuck。



-

-
锻造知识


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.

解决方案

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.

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.


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



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.


Are we permitted a test for zero?

Yes.

One table for addition.

One table for multiplication.

What more tables would you want ?

My mistake I shall correct the mistake:

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.



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.


Are we permitted a test for zero?


Yes.


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.


My mistake I shall correct the mistake:


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


这篇关于基数为256的乘法算法和代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-22 23:40