cpct_setBit

Sets the value of a concrete bit into a bitarray to 0 or 1

C Definition

void cpct_setBit (void* array, u16 index, u8 value)

Input Parameters (6 Bytes, B register ignored, only C register is used for value)

(2B DE) arrayPointer to the first byte of the array
(2B HL) indexPosition of the bit in the array to be modified
(2B BC) valueNew value {0, 1} for the bit at the given position.  If you call from assembly, you can safely ignore B register and set only C register.

Assembly call (Input parameters on registers)

call cpct_setBit_asm

Parameter Restrictions

  • array must be the memory location of the first byte of the array.  However, this function will accept any given 16-value, without performing any check.  Giving and incorrect array pointer will have unpredictable results: a random bit from your memory may result changed.
  • value new value for the selected bit (0 or 1).  Only the Least Significant Bit (LSB) is used.  This means that any given value will “work”.  Odd values will have the same effect as a 1, whereas even values will do the same as a 0.
  • index position of the bit to be retrieved from the array, starting in 0.  Again, as this function does not perform any boundary check, if you gave an index outside the boundaries of the array, a bit outside the array will be changed in memory, what will have unpredictable results.

Known limitations

  • Maximum of 65536 bits, 8192 bytes per array.

Details

Set the new value of the bit at the given position (index) in the specified array.  This function assumes that the array elements have a size of 8 bits and also that the given index is not bigger than the number of bits in the array (size of the array multiplied by 8).  The value to be set is also assumed to be 0 or 1, but other values will “work” (just the least significant bit will be used, so odd values are treated as 1, even vales as 0).

Destroyed Register values

AF, BC, DE, HL

Required memory

C-bindings39 bytes
ASM-bindings35 bytes
bitWeights+8 bytes vector required by both bindings.  Take into account that this vector is included only once if you use different functions referencing to it.

Time Measures

Case       | microSecs(us) | CPU Cycles
-------------------------------------------
Best  (1)  |       55      |    220
-------------------------------------------
Worst (0)  |       57      |    228
-------------------------------------------
Asm saving |      -15      |    -60
-------------------------------------------
Sets the value of a concrete bit into a bitarray to 0 or 1
unsigned int (u16 = unsigned 16-bits, 2 bytes)
unsigned char (u8 = unsigned 8-bits, 1 byte )
Close