Skip to main content
Filter by
Sorted by
Tagged with
2 votes
3 answers
189 views

The following derives from this question but is distinct Consider the following code sample; uint32_t *value = malloc(sizeof(uint32_t)); *value = 0xAAAABBBB; int16_t *subset = (int16_t*) (value); ...
Nil A Curious Programmer's user avatar
3 votes
2 answers
229 views

I'm a beginner working on AVR programming on the ATmega328P. I am trying to get input from a button and then control an LED. void setup() { DDRB |= (1<<PB5); DDRB &= ~(1<<PB4); ...
Toghrul Guluzade's user avatar
2 votes
2 answers
227 views

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() ...
uran42's user avatar
  • 469
1 vote
1 answer
97 views

In a golang project I have defined those uints. They are set to uint automatically by iota: package userrole const ( Reviewee = 1 << iota // 1 Reviewer // 2 Admin ...
Anders Finn Jørgensen's user avatar
5 votes
3 answers
292 views

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 ...
uran42's user avatar
  • 469
3 votes
2 answers
194 views

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 ...
uran42's user avatar
  • 469
0 votes
0 answers
29 views

Given a number with a width of n bits representing a signed number in two's complement, what is the minimal number of bits that need to be checked and which ones, in order to know whether there will ...
Ranar 100's user avatar
0 votes
0 answers
85 views

I have two bitwise expressions and need to figure out which one is faster. Also, if there are other ways to implement the same, but in a faster way than the given expression. I am using these ...
ahmed 's user avatar
  • 11
4 votes
2 answers
273 views

This code doesn't compile. It seems like the compiler (VS) is interpreting the expression as: (std::cout << ul1) & (ul2 << std::endl) #include <iostream> int main() { ...
user8683582's user avatar
0 votes
0 answers
87 views

I need to bit inverse a value in a cell. All I found was the function XOR(a;b) and it would be possible to use a bitwise XOR to invert a value. However, the problem is that that XOR(a;b) only does a ...
Max Kielland's user avatar
  • 5,871
-1 votes
1 answer
61 views

So I'm practicing disassembling on an C program that checks if the user given serial number fulfills the requirements. The program manually checks each character from the serial number, executing the ...
TasH's user avatar
  • 13
1 vote
1 answer
122 views

when shifting bytes, there are some scenarios that do not seem to make sense, for example printf("shifted bytes %llx\n",(((long long)1 << 63 ))>>1); outputs c000000000000000, ...
user20695956's user avatar
-2 votes
1 answer
37 views

I have a field containing an int that represents flags 0 = No error 1 = Error 1 2 = Error 2 4 = Error 3 8 = Error 4 so if I have a value of 5, I know it is Error 1 and Error 3 I need to add custom ...
mark1234's user avatar
  • 1,117
-1 votes
2 answers
146 views

I was trying to solve the exercise that says Exercise 2-7. Write the function rightrot(b, n) which rotates the integer b to the right by n bit positions. and i did code it, here is the code #include ...
Haru Hoshizora's user avatar
-2 votes
1 answer
98 views

I am solving a problem that requires O(1) space complexity to check for duplicate numbers. I wanted to use a hash table, but due to the O(1) space constraint, I used bitwise operations. However, I ...
459zyt's user avatar
  • 115
3 votes
1 answer
148 views

Given an unsigned 64-bit integer y, is there an efficient way to find all unsigned 64-bit integers x such that (x & (x + y)) == 0? Some examples for small y: y=0: only possible solution x=0 y=1: ...
Nicolas Malebranche's user avatar
2 votes
1 answer
211 views

This code won't simply invert the bits of the 16-bit integer as expected: #include <stdint.h> typedef uint16_t U16; U16 myNum = 0xffff; ~myNum // 0xffff0000, not 0x0000 Because C will promote ...
beyarkay's user avatar
  • 1,173
1 vote
0 answers
73 views

I came across the following C++ solution for finding the smallest number greater than n that has the same number of 1's in its binary representation int solution(int n) { int pivot = n & -n; ...
git546's user avatar
  • 11
0 votes
2 answers
353 views

I have an input string read from a device which is an ASCII Hex representation of a 32-bit floating point value. e.g. "4048f5c3" (--> 3.14) My question is how can I turn that into a ...
dsr's user avatar
  • 3
1 vote
5 answers
381 views

I have a basic logic that I can implement with logical operators: if a == true && b == false I am wondering if I can do the same with bitwise operators? XOR does this: 0 ^ 0 = false 0 ^ 1 = ...
aro's user avatar
  • 49
2 votes
1 answer
108 views

I have a snippet of code below that checks whether a register value is set. # define My_register_array(index) (*((P2VAR(uint32, AUTOMATIC, APPL_VAR))Group_register(index))) /*eg: Group_register(...
user2986042's user avatar
  • 1,300
3 votes
1 answer
173 views

Let's say I have an auth field that use bit flags to indicate permissions (example bit-0 means add and bit-1 means delete). How do I bitwise-OR them together? import polars as pl df_in = pl.DataFrame(...
JL Peyret's user avatar
  • 12.2k
-3 votes
1 answer
181 views

I'm trying to understand how the right shift (>>) operator works in JavaScript, especially when dealing with negative numbers. I know that the left shift operator (<<) effectively ...
Aditya Basak's user avatar
35 votes
3 answers
2k views

I was helping a student with his assignment and ran into a very gnarly "bug" which I could not explain, and was wondering if I could get help in understanding what exactly is going on. The ...
elialm's user avatar
  • 781
0 votes
1 answer
145 views

A single 1 byte could be from 0 to 255. I intend to rescale it to be from 0 to 7. I have done this: bit8 := uint8(136) // To re-scale 1 byte from 0 to 2^3-1 i.e. 0 to 7 bit3 := bit8 / 0xff * 0b0111 ...
Megidd's user avatar
  • 8,233
0 votes
2 answers
40 views

I have a case where users may have access to some content with subscriptions, it's not video streaming but I will write an example with that for easier understanding: users in "basic" ...
Uto dev's user avatar
  • 11
-1 votes
0 answers
37 views

I am writing a Java program that performs bitwise operations on bites in a data stream. I have been given test values in the form of 8-digit hexadecimal strings, which I have converted to base 10 and ...
T. J. Foster's user avatar
5 votes
1 answer
441 views

I am working with an assembly language that does not contain either multiply, divide, or bit-shift instructions. I am aware that a left bit-shift can be achieved by just adding the same number to ...
Kestrel's user avatar
  • 73
-1 votes
3 answers
131 views

I have a function that takes two strings and returns another string (if you must know, its my implementation of strjoin). Now, I want to make it so that if one of the input strings is NULL, it will ...
Cab the Kid's user avatar
0 votes
1 answer
58 views

I would like to do an in-place bitwise operation on my dask array i, with a mask cover it. MVE: import dask.array as da i = da.full((10,10),fill_value=4) c = da.ones(i.shape, dtype=bool) c[:,0] = ...
COW's user avatar
  • 1
0 votes
1 answer
98 views

Assuming I have 4 ports that may be on or off, and are represented by the LSBs of a uint8_t mask, meaning 0b00001001 means ports 0, 3 are on. Given a number between 0-3 (which represents the ...
Dan's user avatar
  • 49
0 votes
1 answer
156 views

I am trying to write the following javascript function in python exports.hash = u => { u += 0xe91aaa35; u ^= u >>> 16; u += u << 8; u ^= u >>> 4; let a =...
Jabir Nurul Haque's user avatar
0 votes
2 answers
278 views

I'm just learning how to code and while studying sorting algorithms I was asked to "see if you can combine the two lines in your if and else blocks into one line to make your code look a little ...
Sergio Ruiz Sánchez's user avatar
0 votes
0 answers
443 views

I have the following code, the purpose of it is to find 14 distinct letters in a string of letters. It does it by using a left shift and XOR operator, I don't fully understand why the left shift is ...
MarinaF's user avatar
  • 95
0 votes
3 answers
91 views

For context, I need to write a test for an integer between 0 and 7 inclusive, that evaluates to true for {1,3,4,6} and false for {0,2,5,7}. I thought for a couple minutes about whether there might be ...
gbromios's user avatar
  • 472
1 vote
1 answer
448 views

This might turn to be a stupid question but I really don't understand why clang-tidy is complaining here. Consider the following config: # .clang-tidy --- FormatStyle: file WarningsAsErrors: '*' ...
Slav's user avatar
  • 376
1 vote
1 answer
102 views

I'm reading Computer Systems: A Programmer's Perspective and I don't understand why does bit vector a = [01101001] encode set A = {0, 3, 5, 6}? I did some googling but haven't find anything useful. I'...
not-a's user avatar
  • 87
0 votes
2 answers
78 views

I need to convert LSB 0 to 1 in left shift: x=5; int num = 0x02;//0b00000010 shiftVal = num << x;// 0b01000000 shiftVal should convert to 0b01011111
alex's user avatar
  • 7,963
-1 votes
1 answer
63 views

I am working in a WPF app where I have some Items checked, I am trying to clear the checked items and reset it in the for loop if the is check is true. Using ' fruit.FruitType = NewFruitType.None;' ...
Dev's user avatar
  • 1,856
1 vote
5 answers
811 views

So I got a coding problem, the the program asks me to negate every bit of a binary, for example, the regular bitwise negation will be like this: ten = 00001010 the negation is 11110101 = 245, well to ...
penguinn's user avatar
2 votes
1 answer
375 views

I'd like to AND two vectors of 512 bits containing 8 bit elements. Looking at the Intel Intrinsics Guide I can see some 512-bit AND operations: __m512i _mm512_and_epi32 (__m512i a, __m512i b) __m512i ...
user997112's user avatar
  • 31.1k
0 votes
0 answers
37 views

In order to perform left shift, we have to multiply the left operand with the 2^second operand. For big powers How to perform left shift manually? For small numbers such as 3<<1 It will work as ...
user3214728's user avatar
2 votes
4 answers
187 views

I am a new computer science undergrad. For my assignment I need to implement isNotEqual(int x, int y) function in C by just using bitwise operators. This function will return false if x and y are ...
Alper's user avatar
  • 21
0 votes
1 answer
95 views

I was writing a piece of code for a practice problem where I was trying the display the highest odd number. I kept running into a problem where when I was linking two statements together with a & ...
Jay's user avatar
  • 3
1 vote
0 answers
366 views

Lua 5.1 does not yet support bitwise operators. The Lua environment I'm using is restricted and provides a bit32 library that allows bitwise operations with 32-bit numbers. The issue is that I'm ...
neth's user avatar
  • 19
-1 votes
1 answer
198 views

I had both of these conditions inside an if statement to check if x was even or odd, but the !(x&1) seemed to execute the body of the if in case of an even x, while x&1==0 didn't execute it. I ...
Siddhant Purkayastha's user avatar
1 vote
1 answer
182 views

How many addition operations can be performed instead of a single multiplication on FPGA? In terms of used resources - as an example - energy and logic area cost. I would like to know it for multiple ...
Yevhenii's user avatar
1 vote
2 answers
807 views

Are there unary bitwise reduction operators in C like there are in Verilog? Like in Verilog we have: $display (" & 4'b1001 = %b", (& 4'b1001)); and the output of the function ...
AZ123's user avatar
  • 194
1 vote
0 answers
120 views

Since python has no limit on the number of bits for storing an integer, how exactly does it perform bitwise operations on integers? How many bits does it really store an integer in? RealPython claims ...
Rajdeep Sindhu's user avatar
1 vote
1 answer
79 views

Ok i am using a for loop as show below to convert this data from to the one below using xor accumulate. For the entries i have (830401) rows and this is very very slow. is there any way to speed up ...
oppressionslayer's user avatar

1
2 3 4 5
63