Skip to main content
2 votes
3 answers
164 views

Bitwise operations act outside of type width in C; Compiler Bug or Within Spec?

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
1 vote
2 answers
183 views

Why we use PIN & (1<<PBx) to check if PIN is high?

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

Bitwise operator or converts uints to int in golang

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

Detecting overflow in two’s complement multiplication by 2 – which bits need to be checked

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
76 views

Which of these two bitwise expressions is faster, and is there an optimized alternative?

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
4 votes
2 answers
205 views

Shift "<<" and bitwise "&" operators precedence issue. Why it doesn't compile?

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
54 views

How to BIT inverse a value in OpenOffice Calc?

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,861
-1 votes
1 answer
54 views

Assembly: Character type checking

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
110 views

right shift not working correctly for large longs

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
35 views

Salesforce Bitwise Comparison

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
136 views

Unexpected output from right rotate function

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
94 views

Using bitwise operations to simulate an N-length hash table: is space complexity O(1) or O(n)? [closed]

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

15 30 50 per page
1
2 3 4 5
208