C Operators

% Remainder after division (modulo division) The result of a modulo division is the remainder of an integer division of the given numbers. Examples

Read More

Malloc

Temporary memory example Functions malloc(size_t size) allocates the requested memory (size specified in bytes) and returns a pointer to it. realloc() free()

Read More

Endian

Endianness defines the location of byte 0 within a larger data structure. Little-endian The least significant byte of a 16-bit value is sent or stored before the most significant byte Bits7:0 | Bits15:8 A 32bit value is stored in a byte array as: Byte[3] | Byte[2] | Byte[1] | Byte[0] Big-endian The more significant byte […]

Read More

Two’s compliment / 2’s compliment

Two’s complement is the way most computers represent integers.  The highest bit indicates positive or negative: 0b0xxxxxxx = value is positive or zero 0b1xxxxxxx = value is negative Convert positive value to negative Invert the binary digits and add one to the result. E.g. 1 / 0x01 becomes 0xFE, +1 = 0xFF Convert negative value […]

Read More

Pointers

Basic pointer usage char my_buffer[20]; //Declare an array char *p_buffer; //Declare a pointer p_buffer = &my_buffer[0]; //Load pointer *p_buffer++ = 'H'; //Write to the index 0 in the array *p_buffer++ = 'e'; //Write to the index 1 in the array  

Read More

Converting Variables

Convert float to bytes Convert bytes to float Note, if this appears not to work (you get zero out but with a valid float value in) then try reversing the byte order! Example The following input bytes 0x1f, 0x85, 0x45, 0x41 will produce a float output of 12.345

Read More