Skip to main content

Questions tagged [bit-manipulation]

0 votes
0 answers
39 views

How to check if a hexadecimal addition is correct in two’s complement and whether overflow occurs?

Given this addition, $9999_{16} + 1111_{16} = AAAA_{16}$, I'm supposed to interpret the operands and the result as signed integers in two's complement. How can I tell if the result is correct, and ...
belibel's user avatar
1 vote
0 answers
50 views

How to calculate circular bit difference?

Given two systems with same fixed-bit, e.g. two 8-bits, A and B. How to calculate circular difference? Example, both are using unsigned integer format: A: 250 B: 1 If we perform substraction, ...
Muhammad Ikhwan Perwira's user avatar
1 vote
1 answer
75 views

Detection of faulty row(s) in a matrix

I have the following problem: I have a matrix $M$. Suppose the $n$ rows matrix consists of arbitrary binary values of a fixed length $m$. I can now store redundant information about my matrix. I give ...
Titanlord's user avatar
  • 131
0 votes
0 answers
56 views

How simple addition operation performed with just one instruction by BitBitJump?

According this: https://en.m.wikipedia.org/wiki/One-instruction_set_computer Its instruction has 3 operands, the meaning is: copy the bit addressed by a to the bit addressed by b and jump to the ...
Muhammad Ikhwan Perwira's user avatar
1 vote
1 answer
83 views

Efficient way to implement a bit-wise counter that becomes 1 every (k*n)+i times

My question is about LeetCode "137.Single Number II": 137.Single Number II Given an integer array nums where every element appears three times except for one, which appears exactly once. ...
R. Javid's user avatar
  • 173
0 votes
3 answers
156 views

Is there an algorithm to implement N-input-gates using smaller gates?

To borrow part of a description from a similar but distinct question: there exist 2^(2^N) different functions which accept N binary inputs and return a 1 bit output. For the purposes of my question I ...
HappMacDonald's user avatar
1 vote
1 answer
322 views

Splitting a Larger Unsigned Integer into Summable Parts

I have a very strange (arbitrary) problem that I have been trying to wrap my head around, but have been struggling to figure out how to accomplish this. I'll use Rust but in a pseudo-code fashion, ...
Naftuli Kay's user avatar
0 votes
2 answers
608 views

Why is 2's complement used for representing negative numbers?

So I was reading the use complement operation in the digital logic and found, it is used to give additive inverse of the number and subtracting a number (like we do) is difficult for computer. So it ...
tbhaxor's user avatar
  • 208
0 votes
0 answers
70 views

Exact Definition of simple bit pattern?

I didn't find an exact description for this, but I know that any integer type is a simple bit pattern, it seems to me that the simple bit pattern should have a more exact description as I understand ...
Gor Madatyan's user avatar
1 vote
1 answer
161 views

Faster finding of a subset of bits with all combinations in the bitstrings

Assume that I have a bunch of bitsets (strings on $\{0,1\}$) of the same length, e.g.: 101110001 001001101 010101010 101001001 101010101 I want to find the largest ...
Dmitry's user avatar
  • 346
-2 votes
1 answer
257 views

Find Number of subsequences such that bitwise OR is same as sum

Suppose there is an array having at most 10 elements between 1 to 10^18. Suppose the array has elements B1,B2,.Bn. We can choose sequence A1,A2,A3,..An such that 0<=Ai<=Bi. Count How many ...
abcd's user avatar
  • 1
4 votes
3 answers
6k views

Calculating XOR of all numbers from 1 to n: Why does this method work?

Given a number n, the task is to find the XOR of every number from 1 to n. Why does the following algorithm work? Find the remainder of n by moduling it with 4. If rem = 0, then XOR will be same as n....
MonkaS's user avatar
  • 89
0 votes
1 answer
238 views

Is "Bitwise Complement Operator" (~ tilde) distributive?

To be more precise, Is ~(a+b) = ~a + ~b? Here, "~" bitwise NOT operator. I ran into this question while thinking about ...
siv2r's user avatar
  • 1
0 votes
1 answer
97 views

Number of bit string interpretations correct?

Suppose you are given a bit string $B[1 ... n]$. Now, suppose that some bits are just padding bits conveying no information, the rest of the bits may be permuted and some meaningful (that is, non-...
coderodde's user avatar
-3 votes
1 answer
198 views

Identify the missing number in a set given its superset

Given a set B and B’s superset A, if B is missing 1 number (let’s y) but don’t know which number it is, how to find that number? That is, B’ = B \ {y}, for some unknown element y B = A \ {x}, for ...
Paul Yu's user avatar

15 30 50 per page
1
2 3 4 5
7