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

Iterate through all potential starting positions in Held-karp algorithm utilizing a bit-mask

I am interested in implementing the held-karp algorithm based on a C implementation found here: https://www.math.uwaterloo.ca/~bico/papers/comp_chapterDP.pdf in javascript. However, this implementation uses only a single starting position. I have…
0
votes
3 answers

operator>> and << output being nulled when outputted

i dont understand why the output of both functions are getting nulled when i output them: class uint128_t{ private: uint64_t UPPER, LOWER; public: // constructors uint128_t(){ UPPER = 0; LOWER = 0; } template…
calccrypto
  • 8,583
  • 21
  • 68
  • 99
0
votes
1 answer

logical shift in CUDA

rshift = ((J[i]-1)*((2*net)-J[i]) >> -1); L[i] = rshift + K[i]-J[i]; when i compile this, i get "error: expression must have integral or enum type" corresponding to the first line. except for 'i' all have double precision. it works for neither…
Population Xplosive
  • 581
  • 2
  • 8
  • 18
0
votes
1 answer

how does the binary left shift is behaving after 30 shift in c++?

in C++ int is of 4 bytes that means that int memory it can store 32 bits, then how come int i = 1; i = i<<32; cout<= width of type [-Wshift-count-overflow] i <<=…
Piyush Kumar
  • 191
  • 1
  • 10
0
votes
0 answers

In a bytes object, which is the fastest way to perform a bit shift across bytes?

Another question seems exactly about this, but it is for Java. Even wrongly doing the shift on a per byte basis (local), it is still slower than shifting across bytes (glob) through a conversion to integer: In [394]: def local(ts): ...: …
dawid
  • 663
  • 6
  • 12
0
votes
3 answers

Left shift gives me strange results

#include #include #include int main() { printf("left shift 1 = %d\n", 1 << 1); printf("left shift 2 = %d\n", 1 << 2); printf("left shift 3 = %d\n", 1 << 3); printf("left shift 4 = %d\n", 1 << 4); …
Leo_Wang
  • 67
  • 6
0
votes
2 answers

Java shift operator don't works the same with a pre saved value than with the direct value

This comes up after solve the problem: https://www.hackerrank.com/challenges/flipping-bits/problem?h_l=interview&playlist_slugs%5B%5D%5B%5D=interview-preparation-kit&playlist_slugs%5B%5D%5B%5D=miscellaneous My solution is: static long…
0
votes
3 answers

What happens when you shift an int left

I'm trying to understand part of this code that was created here to create a my_hashset: https://leetcode.com/problems/design-hashset/discuss/548792/Java-solution-faster-than-99 class HashCode_from_leet { int[] bitArr; private static…
Katie Melosto
  • 1,047
  • 2
  • 14
  • 35
0
votes
2 answers

Can we left shift a value inside a while loop?

I try to make use of a left shift to identify a setbit using a counter. When I try to left shift var, I found that it is stuck in an infinite loop and only zero gets printed. What is wrong with the following code? Is it even legitimate to make use…
KJ L
  • 115
  • 2
  • 14
0
votes
2 answers

How can I concatenate integer bit fields in c into a uint64_t integer?

I have a struct in c like this struct RegisterStruct { uint64_t b_0 : 64; uint64_t b_1 : 64; uint64_t c_0 : 64; uint64_t c_1 : 64; uint64_t c_2 : 64; uint64_t d_0 : 64; uint64_t d_1 : 64; }; I would like to concatenate…
Kinyugo
  • 429
  • 1
  • 4
  • 11
0
votes
3 answers

JavaScript optimized version of ARGB to RGBA array conversion

I want to convert an Uint8Array of bytes that contains an ARGB image into its RGBA representation, however I would like to get that with something more opimized than what I propose here, using byte shifting for example. What I do right now is to…
Treviño
  • 2,999
  • 3
  • 28
  • 23
0
votes
3 answers

Conversion between 64-bit and 32-bit fixed-point numbers

How to convert data from Q33.31 format to Q2.30 format? I know that we need to use shift operators if both input and output are of same bit size. But how to calculate if they are of different size?
rkc
  • 111
  • 8
0
votes
1 answer

Why Java isnt calculating logical shift right correctly?

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; System.out.println((z >>> 2)); } } Why Java…
0
votes
1 answer

Mapping specific bits in input bytes to specific bits in output word

Background: Given some input bytes B0, B1, B2, B3 and B4, I want to extract selected bits from these 5 bytes and generate an output word. For example, denoting the nth bit of Bi as Bi[n], I want to be able to write a mapping f : (B0, B1, B2, B3, B4)…
CH.
  • 556
  • 1
  • 5
  • 16
0
votes
0 answers

Reading Sectors from a Floppy Image - Bit Shifting?

I am trying to read and display the disk geometry of a floppy in C. I was able to manage the first few entries (as far as I know of they're correct at least) such as: Bytes per Sector Sectors per Cluster Reserved Sectors for the Boot Record Number…
BpVx
  • 23
  • 6