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
0
votes
1 answer
Store data in Byte array in java
I am trying to convert a string like "password" to hex values, then have it inside a long array, the loop working fine till reaching the value "6F" (hex value for o char) then I have an exception java.lang.NumberFormatException
String password =…

Shadi Jumaa
- 188
- 1
- 11
0
votes
2 answers
How to merge two unsigned chars into a single unsigned short(16 bits) in c++
How do I merge two unsigned chars into a single unsigned short in c++.
The Most Significant Byte in the array is contained in array[0] and the Least Significant Byte is located at array[1] . (Big endian)

thecoder
- 11
- 2
0
votes
0 answers
What does bit shifting a byte array element do in C
I am trying to understand this bit of code.
uint8_t input[4];//Just the relevant bits of code here
unsigned int s = (input[0] << 24) | (input[1] << 16) | (input[2] << 8) | input[3];
So I guess my main question is, is it relevant to keep the first…

Fred
- 1,486
- 1
- 9
- 6
0
votes
1 answer
C function replace a byte in a specific index of a parameter
So I'm using the following code:
unsigned long replaceByte(unsigned long original,unsigned char newByte,int indexToReplace)
{
int shift = 8 * indexToReplace;
unsigned long value = newByte << shift;
unsigned long mask = 0xff <<…

Dima Ciun
- 87
- 1
- 11
0
votes
1 answer
c function to merge bytes in a specific order depended on endianness
I want to be able to merge bytes from two unsigned long parameters, taking exactly half of the bytes, the half that starts with the least significant byte of the second param and the rest of the first param.
For example:
x = 0x89ABCDEF12893456
y =…

Dima Ciun
- 87
- 1
- 11
0
votes
1 answer
Decimal to binary without for, while, or if loops
How can I write a program that reads an integer and displays a binary number without using loops, just with binary operators? (Only with basic functions)
#include
#include
#include
int main()
…

Cristian Bătrînu
- 1
- 2
0
votes
1 answer
I want to know how to approach these functions in C. I have tried solving them but failed
#include
#include
#include
//-- Sign related constants --//
// PURPOSE: To be the mask to only keep the sign bit.
const int SIGN_MASK = 0x80000000;
// PURPOSE: To tell…

Koko
- 57
- 6
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
0 answers
Reversing XOR byte-shifting algorithm
I'm working on this unofficial launcher for an old multiplayer game that used to be hosted by Gamespy (which is dead now). And we're trying to get it playable again for old times sake.
We're using the open source RetroSpyServer to get the server's…

Wouter L
- 1
0
votes
1 answer
How to do bitmanipulation with more values without multiple masks?
I have this assignment and I am not sure how to do this and a simple google wouldn't help me. Also not exactly sure what to search for.
But I'm creating a clock / watch that contains hours, minutes and seconds.
And the bitmask I'm given to use…

Mettepen
- 61
- 5
0
votes
0 answers
How to extract specific bits from an offset
Im attempting to create an assembler in c of a sorts in which i take an input from a file that contains a command, in this case branchifequal i then take its opcode which is 10 so byte[0] = 0xA0 and then i get the register for the next 4 bits and…

Bret Hasel
- 303
- 1
- 11
0
votes
1 answer
C - Walking one and zero test, rotating through carry
I am a student, a couple of years messing about with C but no solid period of practising the language. I am trying to perform a walking one and walking zero test on a byte and pretty stuck, any tips would be appreciated.
I have two questions.
1) How…

MBK
- 13
- 6
0
votes
2 answers
What does using bit wise AND operator on a unsigned char object after right shifting it mean?
I'm trying to understand a snippet of code which is the following:
unsigned char state = portStates[portNumber];
int bitValue = (state >> 7) & 0x1;
It's doing a bitwise AND on the least-significant bit of
state, right? If it returns true (ie, that…

the_naive
- 2,936
- 6
- 39
- 68
0
votes
1 answer
Bit Operation Issue (shifting, masking, ...)
Why does this expression always result in -2,147,483,648 (11111111 11111111 11111111 11111111)? I don't get it.
data[] is a byte-Array filled with some values.
(((int)data[29] & 0x00000001) << 31) | (((int)data[30]&0x000000FF)<<12) |…

Armai
- 162
- 1
- 1
- 10
0
votes
1 answer
Bit manipulation over flow
Given the following formula :
(((a-b)>>3) + c-d+4)<<2
And each variable is a 8 bit register, need to find a few bits need for results will not be OVERFLOW .
I think the answer is 11 .
the biggest number that we can take at (a-b) + the biggest…

Yinon Haver
- 11
- 1
- 4