You are on page 1of 1

value = 0x01ABCDEF;

last_byte = value & 0xFF; // = 0xEF


if (last_byte & 0x40) { // is the 7th bit set? (0x01 = 1st, 0x02 = 2nd, 0x04 = 3
rd, 0x08 = 4th, 0x10 = 5th, 0x20 = 6th, 0x40 = 7th, 0x80 = 8th)
value = value & 0xFFFFFF00; // clear last byte
value = value | 0x3C; // set the byte with 00111100 bits (0x3C is the hex re
presentation of these bits)
}
/////////////////////////////////////////////////////
if ((Value & 0x0800) != 0)
{
// Set the 20 other bits to make the int value a negative one
Value |= 0xFFFFF000;
}
///////////////////////////////////////////////////
var temp
temp = 14 << 2
The variable temp has a value of 56 because 14 (00001110 in binary) shifted left
two bits equals 56 (00111000 in binary
var x : byte = 15;
// A byte stores 8 bits.
// The bits stored in x are 00001111
var y : byte = x << 10;
// Actual shift is 10 & (8-1) = 2
// The bits stored in y are 00111100
// The value of y is 60
print(y); // Prints 60
////////////////////////////////////////////

You might also like