Related to shifting bytes and byte manipulation. There are operators in most of the programming languages to shift bits which could be used to shift bytes.
Questions tagged [byte-shifting]
77 questions
2
votes
2 answers
Make a Integer from 6 bytes or more using C++
I am new in C++ programming. I am trying to implement a code through which I can make a single integer value from 6 or more individual bytes.
I have Implemented same for 4 bytes and it's working
My Code for 4 bytes:
char *command =…

Chandrapal Singh Jhala
- 235
- 1
- 4
- 16
2
votes
2 answers
Converting a list of Bytes to Integer in Prolog
I'm trying to convert a list of bytes to it's corresponding integer. I would like to bind to the second variable as the documenting comment would suggest. I'm printing it out as a temporary hack.
% bytes_int(+ByteList, -IntegerRepresentation)
% …

Hierophantos
- 133
- 8
2
votes
1 answer
How to bypass Go int64 value limits while shifting integers?
I'm trying with Go to get values of KiB, MiB, ..., ZiB, Yib which are respectively KibiByte, MebiByte, ..., ZebiByte, YobiByte.
My code in Golang is:
package main
import (
"fmt"
)
func main() {
s := []string{"KiB", "MiB", "GiB", "TiB",…

Chiheb Nexus
- 9,104
- 4
- 30
- 43
2
votes
2 answers
Bit shifting in python
I want to understand the following code. What kinda shifting 3rd line is doing?
number = 1.265
bits = 8
shifted_no = 1.265 * (2** bits)
If I check the binary format of the results of number and shifted_no :
0011 1111 1010 0001 1110 1011 1000…

blackbug
- 1,098
- 3
- 13
- 40
2
votes
2 answers
Wrong bytes generated to create WAV file
My app needs to generate a audio file and I'm writing the file generator following my last Android version. On Android it uses OKIO to deal with IO and iOS it uses the native NSData.
Every WAV file needs a header to inform some parameters for the…

Pedro Paulo Amorim
- 1,838
- 2
- 27
- 50
2
votes
1 answer
Bit shifting for >32 bit long
I am trying to extract the first 49 bits from a 7 byte array. I approached this byte using masks and bit shifting as follows:
long byteVal = ((decryptedVCW[6] & 0xff)&((decryptedVCW[6] & 0xff)<<7)) | ((decryptedVCW[5] & 0xff) << 8) |…

Seb
- 481
- 2
- 6
- 18
2
votes
1 answer
Dividing without using DIV in Assembly
How can I divide two numbers in Assembly without using DIV instruction but by using shift and add method?
I did that with multiplication and here is my code:
mov bl, 56H ;For example
mov dl, 79H
;start
mov bh, 00H
mov dh, 00H
xor di, di
mov cx,…

Ammar Alyousfi
- 4,112
- 5
- 31
- 42
1
vote
0 answers
Masking and shifting, uint8_t into uint32_t
excuse me if this is a newbie question:
I have four uint8_t variables: first, second, third, fourth.
My objective is to put them in a uint32_t, such as that the uint32_t will be composed as:
fourth-third-second-first, but only putting the first 7…

sine nomine
- 31
- 5
1
vote
2 answers
Bitshift (rotation) with hexadecimal in C
I'm trying to rotate hexadecimal numbers in C. The problem I have is that, with each loop. more zeros occur in the number.
Here is my code:
int main (void) {
int hex = 0x1234ABCD;
for(int i=0; i<12;i++,hex <<=4){
printf("0x%04x %d ",hex,hex…

Timon Doo
- 143
- 12
1
vote
2 answers
Rotate left the last 10 bits in an int
I need to implement a function that rotates left the last 10 bits of an int.
So if an int has value
0b 1111 0000 0000 0000 0000 1100 1100 0000
a left rotation by 2 would give us
0b 1111 0000 0000 0000 0000 1111 0000 0000
A further left rotation by…

scy17
- 61
- 4
1
vote
2 answers
Shifting gives a 1 at the most significant digit
Im currently writing a C function that takes a number from the user and converts it into a binary output. First, here's the code:
void Convert_Number_To_Binary(const int num,char *binary) {
double remainder = num;
//Start from binary[0]…

akBo
- 29
- 6
1
vote
0 answers
is getting msb and lsb using the same mask portable with respect to endianess?
Assuming the following C code runs on a 32 bit platform (so sizeof(int) = 4), is the following code portable between big endian and little endian?
When I ask "is it portable" I mean is the app going to print:
a) on a little endian platform
Address…

Sterpu Mihai
- 486
- 1
- 4
- 15
1
vote
0 answers
How to move marked character based on text selection in javascript
I want to move the marked _#current selected text#_ exactly around the current text has selected. So let's see in an example.
Step 1: still no text has selected, so the String is:
let stringVal = "Hello friends, let's program with…

Muhammad
- 2,572
- 4
- 24
- 46
1
vote
1 answer
Dangers of shifting a char out of scope
Okay,
I wrote a function that takes an unsigned char from a hex file and then shifts it to the left to fit inside a WORD,DWORD or QWORD, like follows:
retVal |= ((unsigned char)(memory[i]) << (8 * j));
(inside a loop, hence variables i and j).
Now…

clockw0rk
- 576
- 5
- 26
1
vote
4 answers
Deserialization of uint8 array to int64 fails but should work
Im going to send a int64 over tcp and need to serialize&deserialize it.
First i cast it to a uin64.
I byteshift it into an uint8 array.
Then i byteshift the array into a uint64
And finally cast it back to a int.
But it returns a different value than…

OptoCloud
- 57
- 9