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

Read binary file and check with matching character in python

I would like to scan through data files from GPS receiver byte-wise (actually it will be a continuous flow, not want to test the code with offline data). If find a match, then check the next 2 bytes for the 'length' and get the next 2 bytes and…
Fakir
  • 139
  • 11
0
votes
1 answer

how to use parameters of function C to rotate right in Assembly code

why i can't use rsi at ror of Assembly code when calling function Assembly from C With error: invalid combination of opcode and operands Help me thank you Assembly code: section .text global en_code en_code: mov ax,[rdi] ror ax,rsi…
0
votes
1 answer

Floating point of fixed point division using Shift Operator in Verilog HDL

I want to ask if it is possible to divide the floating-point or fixed number using the shift operators. I want to divide the floating-point or fixed number in the power of 2? I know for decimal numbers we can use shift operators in Verilog HDL for…
0
votes
2 answers

how can I get bit-by-bit of an arbitrary decimal number

I want to read an int number bit by bit from a list, for example: decimal list: [28,171,3,324,66] first: 28 binary: 100111 second: 171 binary: 10101011 ... I was trying to do the bitwise operation but I don't know the length of the binary(e.g.…
SadSalad
  • 69
  • 2
  • 12
0
votes
1 answer

Why use bit shifting on values before writing to I2C?

I recently bought the PTZ-Camera-controller from arducam, and found a kind of API/Controller software on github (https://github.com/ArduCAM/PTZ-Camera-Controller). The module is integrated with I2C, and has several functions on different registers.…
0
votes
3 answers

15Bit Color Components, Bit shifting

Okay bit shifting is still a bit weird to me. I've got a 16bit value. The first 15 bits are colors and the last bit is alpha. I have done this with 24 and 32 bit colors no problem as they are nice byte size's to deal with, but I cant seem to get…
user245019
0
votes
1 answer

C: Getting the most significant and least significant bits

I am given a 32-bit unsigned integer and I am trying to save the 8 most significant bits from that unsigned integer into an unsigned char. I then want to clear those bits to 0s. That last part can be done with a mask but I am unsure of how exactly…
0
votes
2 answers

Bit shifting with leading 1

When I use the >> bitwise operator on 1000 in c++ it gives this result: 1100. I want the result to be 0100. When the 1 is in any other position this is exactly what happens, but with a leading 1 it goes wrong. Why is that and how can it be avoided?
0
votes
1 answer

Why does bit shifting with equal sign prints out different result opposed to non-equal case?

Why are 01 and 02 case different? char c=0xAB; printf("01:%x\n", c<<2); // fffffeac printf("02:%x\n", c<<=2); //ffffffac printf("03:%x\n", c<<=2);
nonamer
  • 5
  • 2
0
votes
1 answer

Shift loop value to first four bit

I have a question for a not specific programming language. I can use Shifting and Bitwise Operators MyValue is for example 0xF5 (1111.0101). Now I want to count up the first four bits like from 0 up to 15 (each bit…
Stampy
  • 456
  • 7
  • 27
0
votes
1 answer

convert big endian to mid little endian

I have the following big endian in C: int32_t num = 0x01234567; I'd like to convert it to mid little endian like this : 0x45670123 How do I use the bitwise operator to do that in C.
cnm
  • 113
  • 11
0
votes
1 answer

Warning: left shift count >= width of type when reading bytestream into double variable in C++

I'm trying to read a bytestream into a double variable in C++. So my code for this is the following: double foo; foo = bytes[0] | (bytes[1] << 8) | (bytes[2] << 16) | (bytes[3] << 24) | (bytes[44] << 32) | (bytes[5] << 40) | (bytes[6] << 48) |…
Samuel Dressel
  • 1,181
  • 2
  • 13
  • 27
0
votes
1 answer

Why would you perform a Bit-shift twice ((x >> 4) << 4)?

So I am analyzing a Nes-Emulator code and I've come across this line of code that I can't make any sense of: nMapperID = ((header.mapper2 >> 4) << 4) | (header.mapper1 >> 4); Why is header.mapper2 bit-shifted once to the right and then to the…
Artichoke
  • 23
  • 3
0
votes
1 answer

Left Rotate Problem in Even/Odd Sum using Tracer SCO Debugger Assembly

I am stuck on the code below. I have the following code for Tracer and SCO Debugger. I am compiling it using Dosbox and I want to add left rotate to the code but I can't find where to I am trying to ad ROL AX, 1 but it is not working. Let say…
0
votes
0 answers

Is it safe to modify and access the same object in a shift operator expression under the new standard?

As I may know that shift operator << doesn't guarantee the order of evaluation of it its operands so an expression like this: int i = 0; cout << i << i++ << endl; // UB But I think the new standard C++17 adds the shift operator to sequenced…
Maestro
  • 2,512
  • 9
  • 24