<How to replace only 4 bits of 1 byte?> I know I c...
# stackoverflow
u
How to replace only 4 bits of 1 byte? I know I can store and retrieve 2 numbers of 4 bits inside 1 Byte like this : // Store both numbers in one byte byte firstNumber = 10; byte secondNumber = 15; byte bothNumbers = (byte) ((firstNumber > 4) & (byte) 0x0F); secondNumber = (byte) (bothNumbers & 0x0F); But how can I overwrite one of the two numbers (let's say the first one (10)) without touching the last 4 bits (15)? // Store both numbers in one byte byte firstNumber = 10; byte secondNumber = 15; byte bothNumbers = (byte)...