
I need to set a bit but the language I'm programming in doesn't have bitwise operators. Is there an easy way to do this? Currently I'm using:
data = data  (2 ^ bitnumber) * mod(data // (2 ^ ...

Take this line of code for example:
for(int i=n1; ~i; i)
My question is what does the ~i mean. What I already know is the for loops needs the following:
for (type var = ; condition; something to ...

I came across one line of code of JavaScript that had different combination of Logical (AND (&&), OR (), NOT (!)) and Bitwise Operators (AND (&) , OR (), NOT (~)). So, can anyone tell ...

I have this source C:
#include <stdio.h>
#define BLUE 1
#define GREEN 2
#define RED 4
int main(void) {
unsigned short i;
char *array[8] = { "000", "001", "010", "011", "100", "101", "...

Im puting a bitmask over a register read value and execute a logical and on the value.
what i expect is:
clear_reg_val: 00000000000000000100100000000000
My actual output is:
# reg_value is: ...

The two statements below give the same results:
(number & 0x02) >> 1 == 1
((number >> 1) & 1) == 1
Is there any advantage to use one before the other?

XOR can be used to encrypt messages! Suppose that you want to say hello to someone securely, without anyone else knowing. Thanks to ASCII, a message like HI can be represented in decimal as 72 73 or ...

javascript, 2020:
I've never worked with the sharedArrayBuffer, (or bits) and I have some questions. Basically I want to store a set of bools and a small counter (4bit), on a single Int16Array ...

/*
* isTmax  returns 1 if x is the maximum, two's complement number,
* and 0 otherwise
* Legal ops: ! ~ & ^  +
* Max ops: 10
* Rating: 1
*/
int isTmax (int x)
{
int t = x + ...

Say I have 2 sets of bits. Pretend that they are two sets of permissions
Desired Permission
Actual Permissions
I want to know the desired permissions that are not set in actual permissions.
Is ...

I want to use the bits valued at 2^42^8 in a Typed 16Uint array item to use as a binary counter to 16.
0000111100000000 >15
0000111000000000 >14
0000110100000000 >13
...
0000000000000000 ...

In doing a bitwise &, I thought by specifying the digit it would add that digit in the necessary spot, but in python I get the following:
>>> 4&2
0
>>> 4&1<<1
0
&...

I have an enum:
public enum STAR_TYPE {
FAST(255, 255, 255),
NORMAL(190, 190, 190),
SLOW(120, 120, 120);
private int color;
private STAR_TYPE(int r, int g, int b) {
int ...

What I'm trying to do is convert any number up to 2^32  1 that is input by the user to its binary value using only bitwise operators. After much head scratching and tinkering, I've come to this ...

(Moved from https://softwareengineering.stackexchange.com/questions/406813/howtoimplementfnv1ainsqlite)
I'm trying to modify a SQLite query (in Android) to return its results in pseudorandom ...

I have an integer that is 8 bits and I want to distribute these bits into beginnings of 4 integers (4x8 bit) two by two. For example:
bit_8 = 0b_10_11_00_11
bit_32 = b"\x12\x32\x23\54" # > [...

Lets say I have the value 1025 as a byte array and the value 1030 as usize. How would I go about comparing if the byte array is bigger, lesser or equal without deserializing it?
I'm completely stuck, ...

(a&b)^(ab)
how can I simply this, if you can add any reference for learning simplification it will be better

I ran across a code challenge. After I finished it I looked at the other answers. I saw an answer that I am struggling to comprehend.
#define CATCH_CONFIG_MAIN // This tells Catch to provide a main(...

Say I have an unsigned char array of ASCII characters with the binary values:
00001100 00011100 00110100 00111000 00110100 00100100 00010010 00011100 00100100 00010000 00011011 00001110 ...

Say you have two integers, A and B.
int A = 0b0011;
int B = 0b1001;
How do I determine if a 0 in A goes to a 1 in B.
I don't care if a 1 in A goes to 0 in B, or if the bit stays the same, only if a ...

This is my first question, so I hope to do this right.
I have a problem where I have to map a key which can be in the range (0, 1, 2) to select a value from the same range (0, 1, 2). I have to repeat ...

I'm implementing a decoding method from an interface control document, and it requires a change of basis in binary  which is a first for me. The change of basis is as follows (z is what i have, the ...

int main(){
long a = 246;
int b = 5;
int c = a  b;
}
Above code will have this bit pattern:
a = 1111111111111111111111111111111111111111111111111111111100001010
b = ...

I need to calculate the nearest bigger integer devisible by 8. For examples:
for a=0, the nearest bigger integer devisible by 8 is 0.
for from a=1 to a=7, the nearest bigger integer devisible by 8 is ...

I have a legacy C++ code which involves lots of bitwise oeprations. I have to port all that stuff to Scala. Is here some easy way like some library
Edit:
C++ code is as:
static uint64_t const C_MASK ...

I've been stuck on a bonus my professor gave for a couple of days now:
give x^y using only ~ and &
Assume the machine use twos complement, 32bit representations of integers.
I've tried many ...

Is there a way to shift left as well as rotate left a binary number utilizing a series of only AND, OR, & XOR gates?

I am tring to understand some HiveQL code that utilizes the ~ operator as well as shiftleft(), which I know is the bitwise leftshift operator. I broke down the final line such that I apply each ...

I always struggled with bitwise operators and their practical usage. I found an example online for something I am doing in C++ and was wondering what is going on there.
for (int i = 0; i < ...

Hi everyone I´m working on a Skinsegmentation program on Python with OpenCv, this is the code:
import cv2 as cv
import numpy as np
cap = cv.VideoCapture(0)
while(1):
_, frame = cap.read()
...

I just learned about logical shift right. Why my java isnt calculating it correctly?
Example:
public class Operators {
public static void main(String[] args) {
byte z = 16;
...

I'll be forthright about this: this one is for homework. However, as I've already completed the question and was just simply curious about different implementations of what I did, I thought it was ...

I am not sure how to phrase the topic for this question because I am new to bit manipulation and really don't understand how it works.
I'm in the process of reverse engineering a game application ...

I'm trying to make a 'matplotlib' graph out of the following equation : q(x) = (x**2) / (x+1)
I tried this code :
def r(x):
return (x*x) / (x+1)
while x<= 2  x >= 0:
pylab.plot(x, ...

The language I'm currently writing in doesn't have native support for bitwise operations, but I don't know how I would go about doing them with decimal arithmetic.
I know bitwise left shift and right ...

Is it possible to achieve using only bitwise operators, ie without logical/comparison/relation operators?
This would essentially be equivalent to the following.
(a & 1 == 0)  (a == 1)
I ...

Say I have a set of flags, encoded in a uint16_t flags. For example, AMAZING_FLAG = 0x02.
Now, I have a function. This function needs to check if I want to change the flag, because if I want to do ...

I'm trying to count the number of bits that are set to 1 but the total always comes to 1 (or 0 if there's none)
What am I doing wrong?
typedef uint32_t uint;
uint hamm_parity(uint data)
{
uint ...

I know that numbers in JavaScript are stored in IEEE754 format. But when we use integers, particularly bitwise operators, they're represented as two's complement with 32 bits.
So 1 would be ...

So I'm looking at recursion method I'm using to solve code challenge. I believe this might be just a misunderstanding on my part. Here is the recursive function.
public static boolean canSum(...

Ans I am getting 7 2 but I am expecting 7 7 because on line b = b ^ a; value of a is 7 and b is 5
then b ^ a should be 7 which is then assigned to b .
#include <stdio.h>
int main() {
int a ...

This small, seemingly insignificant question, occurred to me recently, but after googling quite a bit, I have been unable to find even an opinion on the subject. Only loops and object sizes are ...

I need to leftrotate 32 bits of an Integer by n in Ruby. I'm trying with the canonical implementation:
class Integer
def rotl32 n
return (self << n)  (self >> (32  n))
...

When I execute an unsigned right shift as follows:
short value = (short)0b1111111111100000;
System.out.println(wordToString(value));
value >>>= 5;
I get 1111111111111111.
So, the value is ...

I'm from a game programming background and I've just come across a bitwise XOR ^. I've seen examples of how it works with integers, but I'm a bit confused about the result with boolean values. I know ...

In a recent project, it involved performing an "or" operation to 2 64 bit bitstrings, but I faced a problem, if the strings were sufficiently large, any bitwise operation would return 0, for example: ...

I have a C program below that will replace a specified bit of a number from another number.
Ex:
Let first no whose bit is to be replaced is:
7 //0000 0111
Second no from whom bit is to be replaced
...

I know that in the header of iso646.h, the following eleven marco constants are defined to provide alternative descriptions of the bitwise and logical operators:
and is a macro for &&.
...

I want to pack lod in 2 bits and x,y,z each in 10 bits (what makes 32bit in summ). So far I coded this https://jsfiddle.net/wgdphzL1/2/:
console.clear();
var mask = 0;
var lod = 3;
var x = 5;
var y =...