Questions tagged [binary-arithmetic]
30 questions
14
votes
2 answers
Function that spreads input
I'd like to know if there is a function $f$ from n-bit numbers to n-bit numbers that has the following characteristics:
$f$ should be bijective
Both $f$ and $f^{-1}$ should be calculable pretty fast
$f$ should return a number that has no…
fuz
- 913
- 6
- 20
12
votes
5 answers
Is 2**x faster to compute than exp(x)?
Forgive the naïveté that will be obvious in the way I ask this question as well as the fact that I'm asking it.
Mathematicians typically use $\exp$ as it's the simplest/nicest base in theory (due to calculus). But computers seem to do everything in…
isomorphismes
- 237
- 2
- 5
10
votes
8 answers
Represent a real number without loss of precision
Current floating point (ANSI C float, double) allow to represent an approximation of a real number.
Is there any way to represent real numbers without errors?
Here's an idea I had, which is anything but perfect.
For example, 1/3 is…
incud
- 551
- 7
- 18
10
votes
1 answer
Computing the number of bits of a large power of integer
Given two integers $x$ and $n$ in binary representation, what is the complexity of computing the bit-size of $x^n$?
One way to do so is to compute $1+\lfloor \log_2(x^n)\rfloor=1+\lfloor n\log_2(x)\rfloor$ by computing an approximation of…
Bruno
- 346
- 1
- 8
8
votes
3 answers
Finding maximum and minimum of consecutive XOR values
Given an integer array (maximum size 50000), I have to find the minimum and maximum $X$ such that $X = a_p \oplus a_{p+1} \oplus \dots \oplus a_q$ for some $p$, $q$ with $p \leq q$.
I have tried this process: $\text{sum}_i = a_0 \oplus a_1 \oplus …
palatok
- 255
- 3
- 5
6
votes
3 answers
Converting function to bitwise only?
I have a function to count upper bits of a 32 bit value. So if a number is 11100011111..., the result is 3 as there are 3 ones in the most significant place before a 0 is hit.
I need to convert the function to use only bitwise operations (no if…
Anonymous
- 61
- 2
6
votes
1 answer
How does binary addition work?
I find binary confusing. I have watched minecraft redstone videos on binary adders, real binary adders, diagrams, etc and yet I have not learned much at all. How does electrons flowing through wires made of gold "add/subtract" to make numbers…
AMDG
- 97
- 1
- 9
6
votes
3 answers
What circuit depth is required to add?
If we suppose that we are given two numbers $a$ and $b$ to add, what circuit depth do we require to add them?
I'm wondering if $a$ and $b$ are $O(n)$, and thus the amount of bits required to store $a$ and $b$ are $O(\log_2(n))$, how much time and/or…
Matt Groff
- 902
- 1
- 7
- 16
6
votes
2 answers
Isn't std::bernoulli_distribution inefficient? Designing a bit-parallel Bernoulli generator
C++11 has a convenient Bernoulli RNG, illustrated at
http://en.cppreference.com/w/cpp/numeric/random/bernoulli_distribution .
However, distilling an entire random integer into a single random bit seems inefficient when the expectation parameter $p$…
Igor Markov
- 323
- 2
- 8
5
votes
1 answer
Double-nested loop with bitwise operation
I have this little exercise:
for ( i = 0; i < 2 * n; i += 2 )
for ( j = 1; j <= n; j <<= 1 )
if ( j & i )
foo ();
(j <<= 1 means j = (j << 1), where << is the bitwise left shift operator. & is the bitwise and operator.)
I am supposed to…
Machta
- 151
- 2
5
votes
2 answers
Are there algorithms or circuits that can implement addition without the need for carry flags
Let two numbers $x,y$ be represented in some digit form (binary, octal, ...): $(x_1 x_2 x_3 \ldots)$ and $(y_1 y_2 y_3 \ldots)$.
Can we add those numbers such that we do not need to carry over: $x_i = x_i+y_i + c(x_{i-1},y_{i-1})$ where…
user13675
- 1,684
- 12
- 19
4
votes
2 answers
Minimizing the full adder - where did this XOR come from?
When minimizing the full adder, I don't understand why $A(\bar{B}\bar{C} + BC)$ reduces to $A\overline{(B\oplus{C})}.$
$(\bar{B}\bar{C} + BC)\to (B\oplus{C})$ is partially decipherable, but why is $(B\oplus{C})$ inverted to…
Tyler
- 143
- 5
4
votes
1 answer
Computing the rank of a multiset after inserting another element
What is the procedure for computing the rank of a multiset after inserting an element?
For instance, lets say we have a set $S = (0,1)$ containing $n = 2$ distinct elements.
The multiset $M = (1,1)$ has rank $5$ because there are $4$ multisets less…
tshar
- 63
- 3
4
votes
2 answers
Japanese Multiplication simulation - is a program actually capable of improving calculation speed? Or am I doomed from the start?
On SuperUser, I asked a (possibly silly) question about processors using mathematical shortcuts and would like to have a look at the possibility at the software application of that concept.
I'd like to write a simulation of Japanese Multiplication…
user17734
4
votes
1 answer
Bitarithmetrics to Base X
I've got the following theoretical problem which puzzles me a bit:
I can obtain a string of n bytes (as octets, one byte = one octet = eight bits) of random data. I need to preserve the randomness while reducing the base from 256 to x where x is…
hakre
- 143
- 5