Questions tagged [bit-shift]

A bit shift operation moves the bits contained in a binary numeral or bit pattern to the left or to the right.

A bit shift operation moves the bits contained in a binary numeral or bit pattern to the left or to the right, often written as << and >> respectively.

For example 4<<3 = 32 and 5>>1 = 2.

A zero shift returns the integer part, e.g. 3.14<<0 = 3.

2051 questions
0
votes
1 answer

Write round() function using bitwise operation?

Ahoy friends. I'm writing some code using the PAWN language (C similar) but i need to optimize the run time. So i wan't to try to use bitwise operations here. I got my function to round integers but i need to rewrite it to take a little time…
FBDIMM
  • 1
  • 2
0
votes
1 answer

NumPy right_shift gives all zeros

I have a = np.array([300, 320, 616], dtype=np.uint16) b = np.right_shift(a, 8, dtype=np.uint8) which results in all-zero b. Can you please explain this behavior?
hovnatan
  • 1,331
  • 10
  • 23
0
votes
1 answer

What is the best way to implement a circular array byte shift in java?

If the shifting is not always the same, i.e I may have to use the same function to resize 2 or 4 characters, what would be a good way to circular shift the values of an array of bytes 2 positions * a parameter? This is what I have so far for(int…
dLobatog
  • 1,751
  • 16
  • 17
0
votes
2 answers

Java bitwise causing strange results

I am trying to use an int to represent a register value. I need various parts of the number (in its binary form) to set the state for control lines etc. My code works fine until I get to number 4096 at which points my boundaries stop behaving. my…
user1752971
  • 55
  • 1
  • 8
0
votes
1 answer

Endianness and shift operator in C language, am I doing it correctly?

The original code works fine, it is : for(i = 0; i < 8; i++){ while(readPortAPin1() == BAIXO); writePortAPin2(value & 0x01); value >>= 1; while(readPortAPin1() == ALTO); } In the first code, if value = 10101010 it will be sent as…
Daniel
  • 107
  • 6
0
votes
1 answer

Little to big endian using multiplication and division - MIPS assembly

I have a school assignment that requires me to convert a word from little endian to big endian in three different ways. One of them is by using multiplication and division. I know that shifting to the left multiplies the number by 2 but i still cant…
user9855534
0
votes
0 answers

implementing << and >> with &, |, ^, ~ only?

Can bitwise left-shift (<<) and right-shift (>>) operators be implemented using only AND (&), OR (|), XOR (^), NOT (~)?
0
votes
1 answer

Performing Arbitrarily Large Bit Rotations on an Integer

I am trying to perform very large bit rotations on non-negative 16-bit integers in Python, however it is very slow. I tried optimizing the process by shifting it by the modulo of 16, but it leaves a bunch of zeros at the end of it. Is there any way…
0
votes
1 answer

Bit Manipulation: Add a bit to the left most corner of a sets of bits

So let's say I had a set of bits in the following order: 00101 which obviously would be equal to 5 Would it be possible to add a 1 on the left corner of the sets of bits such that it would be 100101 which would be equal to 37. (Using Bit…
0
votes
1 answer

Bitwise C - Unpacking signed 10 bit numbers from an unsigned int

I've been asked to create a function which will take an unsigned 32bit int and unpack 3 signed 10 bit ints from the unsigned int. The context for this task was an unpacking function, which took a 32bit unsigned int as input and an array of length 3…
Alex
  • 13
  • 3
0
votes
2 answers

How do I bit shift unsigned long in C?

I've tried everything to figure this out and I don't get what I'm doing wrong. converting to signed makes everything past the numerical hex values and I know if I have an integer I can straight up use "ULL" to convert it and bitshift away but I…
0
votes
1 answer

Logical Rotate without using ROR instruction?

I'm attempting to write ASM that uses a logical right shift to shift a byte over without destroying the bytes at the end, but instead rotating them to the front. Essentially, I'm trying to emulate the ROR instruction without specifically using that…
Connor D
  • 103
  • 1
  • 9
0
votes
2 answers

Python bitshifting to java

I found a python code on github, and I need to do the same thing in java, I have almost converted it to java but I'm getting an warning saying Shift operation '>>' by overly large constant value this is the python code that I'm trying to convert if…
user8193104
0
votes
1 answer

Using bitmasks to determine if 2 or more booleans are set

Assume I have the following booleans: var a; var b; var c; var d; var e; I don't care which specific ones are true, or false, just that at least 2 (or more) are true. Would, or Can I use a bitmask (or generate one from these vars) to determine…
simonw16
  • 960
  • 9
  • 25
0
votes
1 answer

Is it possible to do bitwise operation on multiple successive array elements?

I am working on an old implementation of AES I coded a few years ago, and I wanted to modify my ShiftRows function which is very inefficient. For moment my ShiftRows basically just swaps value of successive array element (represented by one byte) n…
Balocre
  • 175
  • 2
  • 10
1 2 3
99
100