multiplication

VHDL Bit Vector Operators

空扰寡人 提交于 2019-12-11 14:14:28
问题 I'm having a lot of trouble getting some simple math done in VHDL. I'm terrible at this language so if my syntax is stupid or something, I have an excuse :P. I'm trying to implement a very simple random number generator that calculates a pseudo-random number by this formula: seed = (seed*1103515245) + 12345 How I'm trying to do it: Signalss here signal seed: std_logic_vector(31 downto 0) := x"2B4C96B9"; signal multiply: std_logic_vector(31 downto 0) := x"41C64E6D"; signal add: std_logic

Multiplying each element of a list with each element of another list in Scheme programming

限于喜欢 提交于 2019-12-11 07:48:22
问题 i am trying to do the following in Scheme: List<int> list = new List<int>(); List<int> list1 = new List<int>(); List<int> list2 = new List<int>(); list.Add(1); list.Add(2); list.Add(3); list.Add(4); list1.Add(2); list1.Add(4); list1.Add(6); list1.Add(8); for (int i = 0; i < list.Count; i++) { for (int p = 0; p < list1.Count; p++) { list2.Add(list[i] * list1[p]); } } as seen in the code above, I am trying to multiply each element of the first list with every element in the second list. So 1*2,

Batch file multiply positive variables return a negative number

三世轮回 提交于 2019-12-11 06:35:20
问题 I've been working on a Batch polygon area calculator and I got a problem. I need to multiply 2 variables, but sometimes it return a negative number if the two positive variables are large. Here's an example: 999999*999999 returns -729379967 . Code goes below: REM Calc square area :PolySqu Cls Echo Polygon Area Calculator For /L %%P In (1,1,57) Do Echo. Set /P "InputPolygonCalSqu=Enter one of the line's length in cm :" Set /A SquArea=InputPolygonCalSqu * InputPolygonCalSqu Cls Echo Polygon

Predefining multiplication for generics in java

末鹿安然 提交于 2019-12-11 03:23:26
问题 So I'm trying, for all intents and purposes, to realize for myself a java version of C++'s STL algorithm inner_product for vector parameters. So far, my code(which is probably fundamentally wrong) looks like this: public static<T,K> double inner_product(Vector<T> v1, Vector<K> v2) { double isum = 0; for(int i=0;i<v1.size()&&i<v2.size();i++) { isum+=v1.elementAt(i)*v2.elementAt(i); } return isum; } The problem is that the operator * is undefined for the types T, K. However my knowledge so far

How to implement Karatsuba Multiplication in javascript?

喜夏-厌秋 提交于 2019-12-11 03:08:40
问题 I have tried to implement karatsuba algorithm using the below code. The problem starts when the number of digits in x and y(parameters) mismatch as the recursive call doesn't work in that case with the below logic. As of now, am getting the correct output when the number of digits in x and y is the same. To be more precise, I think the problem starts with the calculations of z1 and z3 because that is where the number of digits for x and y mismatches frequently. I also am a bit confused about

Does multiplication take unit time?

有些话、适合烂在心里 提交于 2019-12-11 02:35:58
问题 I have the following problem Under what circumstances can multiplication be regarded as a unit time operation? But I thought multiplication is always considered to be taking unit time. Was I wrong? 回答1: It depends on what N is. If N is the number of bits in an arbitrarily large number, then as the number of bits increases, it takes longer to compute the product. However, in most programming languages and applications, the size of numbers are capped to some reasonable number of bits (usually

Multiplication table with rows and columns

China☆狼群 提交于 2019-12-11 01:48:29
问题 How can I make multiplication table to look like this: http://i.imgur.com/rR6JSua.png ? With my code it only has one column. #include<stdio.h> int main() { int i, j; for(i = 1;i <= 9;i++) { for(j = 1;j <= 9;j++) { printf("%d * %d = %d\n",i , j,i*j); } printf("%d * %d = %d\n",i , 10,i*10); printf("\n"); } return 0; } 回答1: Try This: #include<stdio.h> int main() { int i, j; for(i = 1;i <= 9;i+=3) { for(j = 1;j <= 10;j++) { printf("%2d * %2d = %2d ",i , j,(i)*j); printf("%2d * %2d = %2d ",i+1 , j

How to multiply 32-bit integers in c

主宰稳场 提交于 2019-12-10 21:36:02
问题 Execution of: #define HIGH32(V64) ((uint32_t)((V64 >> 32)&0xffFFffFF)) #define LOW32(V64) ((uint32_t)(V64&0xffFFffFF)) uint32_t a = 0xffFFffFF; uint32_t b = 0xffFFffFF; uint64_t res = a * b; printf("res = %08X %08X\n", HIGH32(res), LOW32(res)); Gives: "res = 00000000 00000001" But I expect: fffffffe00000001. What did I do wrong? Single assignment: res = 0x0123456789ABCDEF; printf("res = %08X %08X\n", HIGH32(res), LOW32(res)); Gives res = 01234567 89ABCDEF Environment: $gcc --version gcc (GCC)

Sympy: Multiplications of exponential rather than exponential of sum

爱⌒轻易说出口 提交于 2019-12-10 21:27:30
问题 I'm searching how to tell SymPy to use a multiplication of exponentials rather than an exponential of a sum. That is, it currently gives me exp(a + b) and I would want to get exp(a)*exp(b). There must be a fairly easy way but I can't seem to find it. 回答1: You could use the expand() function to show the expression with multiplication of bases rather than the sum of exponents: >>> from sympy import * >>> a, b = symbols('a b') >>> expr = exp(a + b) >>> expr exp(a + b) >>> expr.expand() exp(a)

Multiply Adjacent Elements

◇◆丶佛笑我妖孽 提交于 2019-12-10 21:19:12
问题 I have a tuple of integers such as (1, 2, 3, 4, 5) and I want to produce the tuple (1*2, 2*3, 3*4, 4*5) by multiplying adjacent elements. Is it possible to do this with a one-liner? 回答1: Short and sweet. Remember that zip only runs as long as the shortest input. print tuple(x*y for x,y in zip(t,t[1:])) 回答2: >>> t = (1, 2, 3, 4, 5) >>> print tuple(t[i]*t[i+1] for i in range(len(t)-1)) (2, 6, 12, 20) Not the most pythonic of solutions though. 回答3: If t is your tuple: >>> tuple(t[x]*t[x+1] for x