Questions tagged [arithmetic]

Questions about implementing elementary arithmetic operations on a computer with hardware or algorithms. The numbers are often assumed to be in a binary representation, add the [floating-point] tag for arithmetic operations on numbers in a floating point representation.

Computer Arithmetic, a subset of Computer Architecture, deals with methods of representing integers and real values (e.g., fixed- and floating-point numbers) in digital systems and efficient algorithms for manipulating such numbers by means of hardware circuits or software routines.

On the hardware side, various types of adders, subtractors, multipliers, dividers, square-rooters, and circuit techniques for function evaluation are considered.

Software aspects of computer arithmetic include complexity, error characteristics, stability, and certifiability of computational algorithms.

Reference and further learning: https://www.ece.ucsb.edu/~parhami/pubs_folder/parh02-arith-encycl-infosys.pdf

297 questions
18
votes
4 answers

Confused about XORing and addition modulo $2$

It's my understanding that when you XOR something, the result is the sum of the two numbers mod $2$. Why then does $4 \oplus 2 = 6$ and not $0$? $4+2=6$, $6%2$ doesn't equal $6$. I must be missing something about what "addition modulo 2" means, but…
snerd
  • 394
  • 1
  • 2
  • 9
12
votes
3 answers

How does 0 have two values in one's complement?

It is said that in 2's complement 0 has only one value, while in 1's complement both +0 and -0 have separate values. What are they?
user136782
  • 223
  • 1
  • 2
  • 5
6
votes
2 answers

Arithmetic network to compute floor of binary logarithm

I wonder how to build efficient arithmetic network (using logical gates only) to compute floor of binary logarithm of the given input number. I have read some articles on stackoverflow.com about this problem, respectively its implementation in C/C++…
Speedding
  • 199
  • 1
  • 7
5
votes
1 answer

Division modulo a prime in modular arithmetic

I am looking for a way to implement division in modular arithmetic using modulo prime. The method I found in math books is to try $u$ such that $au \equiv 1 \pmod{p}$ $b/a \equiv bu \pmod{p}$ where $a, b, u \in Z_p$ (remainder class modulo a prime…
A123321
  • 237
  • 1
  • 2
  • 8
4
votes
1 answer

How many bits to represent a quantity $\omega$ bounded in a particular way?

I'm working out some details to implement a division algorithm, I'm following the explanation given in this book (chapter 5) for who is interested. Anyway I need to work out how many bits are necessary to represent a value $\omega$ bounded by $$ |…
user8469759
  • 713
  • 3
  • 17
4
votes
1 answer

How to represent calculable real numbers?

Suppose I want to do arithmetic without any loss of precision. Floats and doubles are inappropriate. I want to use dynamic memory allocations to store any real number obtained after a finite amount of finite operations (addition, subtraction,…
user102180
3
votes
2 answers

Why does the app I downloaded say that 1 in binary is 00110001?

I've just started learning binary so mind me if I'm bad at this. I think that the binary for 1 ought to be just "1" but, when I key it in to an app I downloaded, the answer has extra 0s and 11s in it. Why?
user142208
  • 31
  • 1
2
votes
2 answers

1's complement addition of outer carry to the result

Let's take for example this addition: 3 + (-1). 1 in binary is 001, and to obtain it's 1's complement counterpart we flip the bits. So it is: 110. 3 in binary is 011. 011 + 110 = 1001 That first 1 which is in bold has to be added to the number…
Iulian Barbu
  • 23
  • 1
  • 4
2
votes
2 answers

Quick way to do bit AND mapping

By writing out a number in binary I can arrive at the value of taking the first x number of bits out of it. For example 00001101 (13) taking the first 6 bit would be 3 taking the first 5 bit would be 1 …
2
votes
4 answers

Does a shift operation distribute over XOR

In this question, we abuse the mathematical notation to express bitwise operations in the following way: $\ll$ is a binary left shift $\oplus$ is a bitwise XOR $0b1, 0b110, 0b10 \ldots$ are used to denote raw bits $repr$ is a function associating…
Morwenn
  • 304
  • 2
  • 11
2
votes
1 answer

Alternative Method for Computing Two's Complement Binary -> Decimal

I proposed this method of converting a two's complement binary number to decimal to my professor and he said it was wrong. Some older guy in the class just shook his head at me and gave me a condescending stare. I'm willing to admit I'm wrong when…
dgreenheck
  • 165
  • 3
2
votes
1 answer

Does last carry bit get added onto the sum calculated by full adder?

Note: This problem is from Introduction to Computing Systems: From Bits and Beyond(2nd) edition, 3.15, page 86. The Problem: I was able to do the problem and ended up with sum being 0010 and the last carry bit of 1. Using a tow bit full adder,…
1
vote
1 answer

Binary Equivalent vs. Computer code(Ascii or UTF)

Does computer convert every stuff using Ascii or UTF? Meaning if there is a mathematical calculation including 65 (as a number) will it convert it into binary (00100001)? And then how it differentiate it with 'A', whose code point is also 65 with…
Kartik
  • 11
  • 1
1
vote
1 answer

The logic behind one's complement addition

For my computer science class I need to finish a project where I desperately need to understand logic of one's complement and two's complement. I already know how to construct these and also how hardware adder works when dealing with two's…
fifco
  • 11
  • 2
1
vote
1 answer

Twos complement arithmetic

If I have the expression: 1011 0000 1110 -1000 1110 0001 ---------------- Then, I find the twos complement of the second number: 0111 0001 1110 +0000 0000 0001 --------------- 0111 0000 1111 I then add this to the first number: 1011 0000…
smollma
  • 131
  • 4
1
2