8,023 questions
-1
votes
3
answers
91
views
Python Bit Shifting [closed]
Assume I have a 1 source variable (int) which is 10 bits long. Let's call it src.
I have 2 destination variables (int) which are 8 bits long namely byte1 and byte2.
MSB LSB
src ...
19
votes
9
answers
3k
views
How to clear specific byte values inside a 64-bit value without looping
Suppose I have this value, with underscores for clarity:
0x12_23_45_09_45_11_23_10
I want to zero out all instances of 0x10, 0x23 and 0x45 inside it, making this number:
0x12_00_00_09_00_11_00_00
Is ...
2
votes
2
answers
215
views
Bitwise division in C : Programme seems to work for other numbers but when the divisor is 0 it returns 11 for no apparent reason
I am trying to solve the problem posed in this question which asks that division of two numbers be performed in a bitwise manner. So, I wrote the following functions.
sum() adds two numbers.
larger() ...
5
votes
3
answers
273
views
Finding the bigger number using bitwise operation in C
I am trying to write a computer programme that will take two numbers from the user as inputs and will print the bigger number using bitwise operation. I want it to end the programme and return 1 if ...
5
votes
1
answer
233
views
"Repacking" 64 to 40 bits in AVX2
I have an array of 64-bit words, which I need to compact by removing the most significant 24 bits of each 64-bit word. Essentially this code in pure C:
void repack1(uint8_t* out, uint64_t* in) {
...
6
votes
4
answers
257
views
How to unpack a buffer of 12-bit values into an array of normalized float32
A measurement system (in our lab) produces data of 12 bits per sample in a packed format, i.e. 2 samples of 12 bits each are packed into 3 bytes:
buf[l + 2] | buf[l + 1] | buf[l + 0]
7 6 5 ...
-4
votes
2
answers
89
views
Is there a name for the high and low bits of a hex string?
In the hex byte A1 B2 C3 D4, ABCD would be the most significant bits of each pair, and 1234 would be the least significant. I find that these groups of bits are often operated on together in hardware-...
3
votes
2
answers
183
views
Programme works but says "warning: integer constant is so large that it is unsigned", solution?
I am trying solve the problem posed in this question that asks << 1 operation be performed on a 64 bit number using NAND operation only and without using any arithmetic operation. My attempted ...
2
votes
1
answer
165
views
Why do bit manipulation intrinsics like _bextr_u64 often perform worse than simple shift and mask operations?
I'm working on performance-critical code and experimenting with different ways to extract bit fields from 64-bit integers. I expected that using intrinsics like _bextr_u64 (Bit Field Extract) would be ...
2
votes
1
answer
170
views
Fast bithacked log2 approximation
In order to estimate entropy of a sequence, I came up with something like this:
float log2_dirty(float x) {
return std::bitcast<float>((std::bitcast<int>(x) >> 4) + 0x3D800000)) -...
-3
votes
2
answers
125
views
Bit Manipulation [closed]
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
int main(void) {
int v;
int sign;
sign = -(v < 0);
printf("%d", sign);
}
Why ...
5
votes
2
answers
197
views
Inconsistent bitwise shifting result in C code
I'm writing a C program and need to create a bitwise mask that could potentially fill a computer word (64 or 32 bits) with all 1s. I found a bug in my code but I can't make sense of it because when I ...
2
votes
1
answer
249
views
Difficulty in understanding the logic behind a problem based on bitwise computations
As part of a test I was given, I am required to code the instructions below:
A function F(x) is defined over integers x >= 0 as:
F(x) = ∑ [(x | i) - (x & i)] (summation ∑ is over i),
with i ...
-2
votes
1
answer
108
views
How to perform bitwise operations on very large integers in Python with only built-in modules [closed]
I'm making an implementation of the SHA-1 algorithm in Python for a school project. My code breaks because it generates an integer too large for my school's IDE to handle.
***I only have access to ...
-1
votes
1
answer
162
views
Counting the number of set bits
this is the problem(counting bits)from cses i have attached the link here https://cses.fi/problemset/task/1146/
the goal of the problem is to calculate the number of set bits in all the number from 1 ...