integer-arithmetic

implementing school-like division on 32bit chunks on x86

丶灬走出姿态 提交于 2019-12-11 20:23:20
问题 Say i got two big numbers (defined below), and i want to implement division on them by falling back to x86 avaliable arithmetic 0008768376 - 1653656387 - 0437673667 - 0123767614 - 1039873878 - 2231712290 / 0038768167 - 3276287672 - 1665265628 C=A/B Those numbers are stored as vectors of 32 bit unsigned ints. First one, A, is 6-unsigned-int vector, B is 3-unsigned-int long vector [each of this field i name generalised 'digit' or 'field' on my own] The resulting C will be some 3-unsigned-int

Printing multiple integers as one arbitrarily long decimal string

偶尔善良 提交于 2019-12-11 18:33:25
问题 Say I have 16 64-bit unsigned integers. I have been careful to feed the carry as appropriate between them when performing operations. Could I feed them into a method to convert all of them into a single string of decimal digits, as though it was one 1024-bit binary number? In other words, is it possible to make a method that will work for an arbitrary number of integers that represent one larger integer? I imagine that it would be more difficult for signed integers, as there is the most

Improved binary division algorithm in MIPS

两盒软妹~` 提交于 2019-12-11 12:19:58
问题 The concept of binary division in MIPS has been explained in the Pattern's computer organization book. However, when I comes to the improved division algorithm, things are not very clear. Consider the following diagram. While it is talking about 32-bit integers, I want to know what are the register sizes for 1001010÷1000 ? Here is my understanding: Dividend: 1001010 which should be 8-bit 0100,1010 Divisor: 1000 which should be 8-bit 0000,1000 Now what about the registers in the diagram?

operations with different int types

安稳与你 提交于 2019-12-11 02:24:55
问题 I have a program which uses multiple different int types. Most often used are uint64_t and the standard int . However I wonder if I can safely do operations mixed between them. For instance I have an uint64_t and I want to add an int to it and store that value as another uint64_t . Is doing such a thing safe? Do I have to cast the int to uint64_t before I can use operations on it? I can`t really find stuff about it online. It might just be allowed and no one questions it or my Google queries

What's wrong with this c program? Debugging it suggests that the program is struck at while (sqroot != 0); [duplicate]

余生长醉 提交于 2019-12-10 23:58:18
问题 This question already has answers here : Is the code “while(condition);” valid and what does it mean? (16 answers) Closed last year . Here's a screenshot of debugging process I am learning to program in C. I am trying to find if a number is a mirror image or not, But the program compiles error-free yet didn't give the desired result. Debugging the program shows that it struck at while (sqroot != 0); // Mirror number #include <stdio.h> #include <math.h> int main() { int num, rev1, rev2, rem1,

How can i do arithmetic operations in one TextBox?

独自空忆成欢 提交于 2019-12-10 18:07:38
问题 For example i write in TextBox1 4*5 or 3-2 how can make the answer appear in the same textbox ? I tried this but it did not work anyway Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click textbox1.text = val(textbox1.text) end sub it just shows the first number 回答1: This is a rather complex task for which there is no built-in support in the VB.NET language. The first step is to parse the text into an expression tree. The second step is to evaluate that expression

Explanation for this function's output

不打扰是莪最后的温柔 提交于 2019-12-10 14:21:56
问题 I am doing review questions which ask me "What is the output of the following," and I am having some trouble understanding something about this function: int a = 1, b = 1, c = -1; c = --a && b++; printf("%d %d %d", a, b, c); The output is 010. My question is about line 2, c = --a && b++ . How is this line processed, and how does it work/change the values? And if it were c = --a || b++ ? From my understanding I thought the output would be 020. 回答1: The key concept to understanding the result

C array arithmetic and pointers [duplicate]

試著忘記壹切 提交于 2019-12-10 14:16:20
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: In C arrays why is this true? a[5] == 5[a] I am reading through a tutorial on C and I came across this syntax: int doses[] = {1, 3, 2, 1000}; doses[3] == *(doses + 3) == *(3 + doses) == 3[doses] Now the point is to get the int 1000 , but the last one doesn't make any sense. Either its late and my brain is not functioning, its something specific to C, or its a typo. I want to cover all my basics when it comes to

Panicked at 'attempt to subtract with overflow' when cycling backwards though a list

為{幸葍}努か 提交于 2019-12-08 14:39:11
问题 I am writing a cycle method for a list that moves an index either forwards or backwards. The following code is used to cycle backwards: (i-1)%list_length In this case, i is of the type usize , meaning it is unsigned. If i is equal to 0, this leads to an 'attempt to subtract with overflow' error. I tried to use the correct casting methods to work around this problem: ((i as isize)-1)%(list_length as isize)) as usize This results in an integer overflow. I understand why the errors happen, and

How implicit conversion work with signed character and unsigned int? [duplicate]

淺唱寂寞╮ 提交于 2019-12-08 14:20:06
问题 This question already has answers here : Why is an unsigned int 1 lower than a char y -1? (2 answers) Closed 7 months ago . #include<stdio.h> void main() { unsigned x = 1; signed char y = -1; if(x > y) printf("x > y"); else if(x == y) printf("x == y"); else printf("x < y"); printf("\n"); printf("%d",(signed char)x); printf("\n"); printf("%d",(unsigned int)y); } OUTPUT: x < y 1 -1 I expected the output to be x == y as during comparison signed character is supposed to be converted to unsigned