Let us say that byte1 = 00001111, and byte2 = 11110000. How would I take the second half of byte1, then take the first half of byte2 and combine them to get one byte of value 11111111. I have done some research, but I just cannot seem to wrap my head around bitmasks and shifting.
How to combine two halves from two bytes to get a single byte
1.2k Views Asked by Hobbs2000 At
1
There are 1 best solutions below
Related Questions in BYTE
- What is the best way to send XML converted to a byte array over TCP, then translate the response back to readable XML?
- Python 3.4 decode bytes
- Display byte array as image
- how to convert an image to byte array in android
- Byte arithmetic and manipulation of PHP string
- C++ How to create byte[] array from file (I don't mean reading file byte by byte)?
- Function to XOR two 128 bits. How do I generate 128 bit values?
- Java byteArray equivalent in JavaScript
- Int to Byte with same value
- Populating data from a binary stream using byte array in java
- How to incrementally iterate through all possible values of a byte array of size n?
- Do the common terminal operations not work with Stream<java.lang.Byte>?
- Lua - Is it possible to check if 2 functions are equal?
- When do I have to cast to byte when initialize a byte array in java?
- mvc c# file upload as byte array
Related Questions in BIT
- How to compare a certain value to value in array?
- How to convert bit string into integer?
- SQL Server 2012 How to change the data type of a column from bit to datefield?
- C++: digits vs bits?
- Data transfer between fpga (14 bits) vhdl block to NIos II system (16 bits)
- Function to XOR two 128 bits. How do I generate 128 bit values?
- Setting a bit in hexadecimal number
- Last two bits in a BitArray of length 4 are being ignored when converting to int
- VHDL OR logic with 32 bit vector
- Endianness for length shorter than word but more than a byte
- Count number of 32-bit numbers in binary file
- Bulk insert CSV with as last column datatype bit
- Why is the big O runtime of 1D parity checking log(n)?
- Having trouble understanding a portion of code
- Bit Pattern in JavaScript
Related Questions in BYTE-SHIFTING
- Best way to shift an array in C?
- bit shifting signed integer
- How can I convert 16 bytes of data into 2 pieces of 8 bytes of data?
- What does bit shifting a byte array element do in C
- Bitshift (rotation) with hexadecimal in C
- Shifting with floats
- Creating a ISO-8859-1 string from a HEX-string in Java, shifting bits
- Android Kotlin Byte Shifting +=
- Swapping 2 Bytes of Integer
- Why left shifting in java changing the sign value
- Shifting binary number in c++
- Rotate left the last 10 bits in an int
- retrieving bits from bytes
- Bit Operation Issue (shifting, masking, ...)
- How to combine two halves from two bytes to get a single byte
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
If it's guaranteed that the "spare" bits are all zeroes, you can just
ORtogether the two bytes, sinceA or 0 == A(see below)If that's not guaranteed, you need
(byte1 AND 0x0f) OR (byte2 AND 0xf0).The
ANDoperations set the unwanted bits to zero (sinceA AND 0 == 0) and then theORoperation combines the bytes, as above.and then
No bit shifts are required because the bits you want to keep are already in the correct bit positions.