bitFieldInsert()
Purpose
Insert a number of bits into a binary number
Description
Insert the specified bits into a 32 bit signed binary number starting at the specified bit
Syntax
result = bitFieldInsert( number, start, count, value )
Arguments
number 32 bit signed binary number
start Start position (first position is 0)
count Number of bits to insert
value Bits to insert
result resulting number when bits have been inserted
Example
loop
textSize( 50 )
byte1 = 0
byte2 = 15
printAt( 0, 0, "byte1 = ", bin2str( byte1 ) )
printAt( 0, 1, "byte2 = ", bin2str( byte2 ) )
result = bitFieldInsert(byte1, 2, 4, byte2)
printAt( 0, 2, "bitFieldInsert( byte1, 2, 4, byte2 ) = ", bin2str( result ) )
update()
repeat
function bin2str( byte )
result = ""
for i = 0 to 8 loop
bit = byte & 1
if bit then
result = "1" + result
else
result = "0" + result
endIf
byte = byte >> 1
repeat
return result
Associated Commands
bitCount(), bitGet(), bitSet(), bitFieldExtract(), bitFieldInsert(), leadingZeroes(), trailingZeroes()