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

How to do implement Hive's Bitwise Left Shift in AWS Athena/Presto?

I am using AWS Athena to query my data and I need to do a Bitwise Left Shift operation. How can I implement this in Athena? More context: I am trying to keep track of events using bitwise operations (shifting bits to the left where 1 means my event…
Diego Serrano
  • 846
  • 2
  • 15
  • 34
0
votes
0 answers

Bitshifting in VHDL creates errors

I am trying to bitshift a std_logic_vector, but no matter what I try, I always get an error. I I have tried to use srl and also shift_right, which I read is safer to use. Both of them are not accepted by the compiler or at least I am making a syntax…
neolith
  • 699
  • 1
  • 11
  • 20
0
votes
1 answer

How to shift the entire 2D array

I am trying to drive an LED matrix and have an issue with shifting the whole display down. My end goal is to shift all of the rows and hopefully eventually implement a wrap around. The problem is that the first row is copied every time each row gets…
RytisBe
  • 69
  • 8
0
votes
1 answer

Left shift operation with Ones' complement binary

I'm in researching about bitwise operation and signed number representations​. I've recognized that if we do left shift on ones' complement pattern. It does not correctly multiply the original number. For example (Ones' complement): 11100101 (-26)…
0
votes
2 answers

Right bit-shift adds 1 to start of unsigned int in C

I'm attempting to shift a 16 bit address to get a set ID for a cache simulator in C, but when I try and bit shift right I get an extra 1 stuck onto my number. I have the number 0010100010011001. I then shift to the left 3 digits to get…
astrachan
  • 9
  • 2
0
votes
1 answer

C# extract bit ranges from byte array

I need to extract some bit ranges from a 16-byte value, e.g.: bit 0 = first thing next 54 bits = second thing next 52 bits = third thing last 21 bits = fourth thing .net doesn't have a UInt128 structure, well it has the BigInteger class, but I'm…
Tony
  • 3,587
  • 8
  • 44
  • 77
0
votes
3 answers

C++ left shift operation

Here is my code int a=2147483647; int b= a<<1; cout<<"a="<
T.g
  • 169
  • 2
  • 11
0
votes
1 answer

C Array: How can I shift each character in a string?

I am new to C, and I am learning shift operation. I understand the shift operation if the data is a binary number, but for my code in this case, I want to implement the case that 't', 'h', 'i', 's', ' ', '\0' are all discarded or shifted, and move…
DigitalSoul
  • 139
  • 1
  • 8
0
votes
1 answer

Problem with reading certain amounth of bits from stream

I have code which reads blocks of bits with size from 1 to 8. Homewer, it doesn't work right. private byte BitRead = 8; private ushort ValRead = 0; private byte[] And = new byte[] { 0x00, 0x01, 0x03, 0x07, 0x0F, 0x1F, 0x3F,…
user8894877
0
votes
1 answer

trouble with grabbing tag bits

I'm implementing a direct mapped cache using python which is direct mapped. Each line in cache contains 4 bytes. I'm having trouble for some reason with pulling out the first (in this case) 27 bits, and also the last 5 bits by using bit…
0
votes
1 answer

Merge 2 integers into 1 byte

I have been working in this since yesterday and I can't seem to fully understand the bit shifting. What I'm trying to accomplish is that, I need to merge 2 numbers into 1 byte. The first number in the 1st four bits, and the second in the last four…
TerribleDog
  • 1,237
  • 1
  • 8
  • 31
0
votes
2 answers

How to replace the the least significant bit (LSB) with most significant bit (MSB) in C

I have just started c-programming and I have a problem to replace the least significant bit (LSB) with the most significant bit (MSB). For example, the first key (key is 32 bit) is 11110000, and after the transformation, it would be 11100001, and…
L0KiZ
  • 69
  • 1
  • 2
  • 7
0
votes
1 answer

How to convert binary to hex using bit shifting/masking

I am trying to convert a string representation of a 32 bit binary number to a string representative of the hex value of that number in a function called hexConversion(). To do this, I am required to use only basic C programming (for loops, basic…
d827
  • 79
  • 7
0
votes
2 answers

Bit Shifting - Why is this code using 24, 16, and 8 right shift?

I am looking at this java code and trying to understand it. I understand everything about it except the bit shifting part. I know the code below that uses bit shifting is building some values to fill up in the byte[] but I dont know why…
cd491415
  • 823
  • 2
  • 14
  • 33
0
votes
1 answer

The right order of shifting bits in c

What is the difference and why are there 3(???) different results? signed char b; b = 66 << 2 >> 8; fprintf(stdout, "%d\n", b); Output: "1" signed char b; b = 66 << 2; b = b >> 8; fprintf(stdout, "%d\n", b); Output: "0" signed char b; b = 2 >>…
homior
  • 161
  • 1
  • 12