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

difference between integer <<32 and <<31<<1

int exp1 = ((1<<31)>>31)<<32 // output changes everytime int exp2 = ((1<<31)>>31)<<31<<1 // 0 why is this happening? it may be caused by overflow thing, but cannot understand properly. I am trying to solve this problem for hours, need some…
jwkoo
  • 2,393
  • 5
  • 22
  • 35
0
votes
2 answers

Trying to shift each bit in a string

Trying an encode program that will shift the ascii code in each character in a string and print out the the new character so that later I can shift left and decode a message. example "#" = 35 or 100011 100011 shifted left once = 1000110 or 70 Then I…
0
votes
1 answer

Enumerate integers by Hamming weight, modulo bit shifting

I need to sample integers from an ordered array described as follows. Let k be a positive integer. All entries are nonnegative integers in [0,2^k) The list starts at 0 All the (increasing) integers with hamming weight 1 modulo bit shifting (i.e.…
0
votes
1 answer

Why is it allowed to keep the bottom word of nextLong() signed?

The java.util.Random class has a method nextLong() which on it's own calls next(32) returning a random signed integer. public long nextLong() { // it's okay that the bottom word remains signed. return ((long)(next(32)) << 32) +…
Kilian
  • 1,540
  • 16
  • 28
0
votes
1 answer

Synthesizable arithmetic shift in Verilog

I recently came across this answer on stackoverflow. With Verilog, once you take a part-select, the result is unsigned. Use the $signed system task on the part select to make it signed. Is this method synthesizable (ie the system task $signed)…
Parth K
  • 587
  • 5
  • 18
0
votes
1 answer

Atmega32 shifting PORTA won't cycle through entire register

I am trying to create a program to flash an LED on each bit of a development board for PORTA using a shift. When I simulate the program, instead of a shift between bit 0-7, the output is 0x01, 0x02, ox04, 0x10. Then it starts over. Is there some…
shark38j
  • 114
  • 13
0
votes
1 answer

Shift masked values of to the end of a 2D python array?

Suppose that we have a 2D numpy array and we use np.ma.masked_where to mask some elements. In each row, we want to move all the masked elements to the end while preserving the order of rest of the elements. Is there an easy loop-free way to do…
Joe
  • 79
  • 3
0
votes
2 answers

Fully explaining bitwise clearing bits

I've been running through the logic of clearing bits and I don't really understand it. Here is what I have so far, where TIMSK0 is a register and TO1E0 is the least significant bit inside TIMSK0 TIMSK0 &= ~(1<
0
votes
3 answers

Multiply by 27 using only bit shifting, addition and subtraction as few times as possible

I recently had a C# technical assessment for a job application where one of the questions was: Question 11: Implement the function int Mult27(int a) such that it returns the result of a multiplied by 27. Do so using only the following functions…
evm87
  • 13
  • 1
0
votes
2 answers

Error with Bit Shifting in C while Accessing Odd Index of Array

I am currently sending an array of unsigned, 8 bit integers to a C program through Bluetooth (as a characteristic). When this packet is received, I want to take a pair of the indexes and "concatenate" their numbers, like so: Input: [0xDE, 0xAD, …
Ryan Moeller
  • 151
  • 2
  • 11
0
votes
1 answer

.shift() apparently no longer exists

https://jsfiddle.net/a/2L4t9saq/217/ is my fiddle most of the code you can ignore, here is the function: var modGrid = function(code){ var arr = code console.log(arr) for(var n=1;n
chaps
  • 105
  • 8
0
votes
0 answers

PHP Bitwise and Javascript Negative Number

I have this function on javascript function b(e, t) { return e << t | e >>> 32 - t } function c(e, t) { var n, r, a, o, i; return a = 2147483648 & e, o = 2147483648 & t, n = 1073741824 & e, r = 1073741824 & t, i = (1073741823 & e) +…
0
votes
0 answers

How to shift left n bits from 16 bytes array?

I have a 16-byte array, and am trying to left-shift the number of bits - where the number to shift can vary from 1 to 10. I tried the code below, but it only works with a 4 bit shift: Rx_Table[16] = {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0A,…
kooda
  • 11
  • 8
0
votes
2 answers

using Bit Shift operations to convert from decimal to hex in Java

If I convert decimal 127 to hexadecimal in Java it will be 7f. I can get the same output using: (1 << 7) - 1 = 127 0x7F = 127 I am trying to convert a decimal value 36028797018963967. In hex it will be: 0x7fffffffffffff How can I represent this…
Cork Kochi
  • 1,783
  • 6
  • 29
  • 45
0
votes
1 answer

64 bit shifting of a modbus register in python

I am trying to get data from SMA cluster controller through a modbus protocol. The modbus specification is something like.. Addres:30517 Desc: Energy fed on all conductors.. , CNT(Word): 4(Number of assigned Modbus registers.) , Type: U64(i need to…
Hsn
  • 1,168
  • 2
  • 16
  • 39
1 2 3
99
100