embedded:c
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revision | |||
| embedded:c [2025/09/11 14:44] – [VARIABLES] v1ctor | embedded:c [2026/03/06 13:16] (current) – [VARIABLES] v1ctor | ||
|---|---|---|---|
| Line 49: | Line 49: | ||
| printf(" | printf(" | ||
| </ | </ | ||
| + | |||
| + | ==== PRINTF FORMATTERS ==== | ||
| + | |||
| + | * %u - unsigned | ||
| + | * %lf - double | ||
| + | * %f - float | ||
| + | * %le, %e - real number in the scientific representation | ||
| + | * %#x - hexadecimal with a leading 0x | ||
| + | * %s - string | ||
| + | |||
| + | ==== ASCII == | ||
| + | |||
| + | <code c> | ||
| + | char a1 = ' | ||
| + | </ | ||
| + | |||
| + | If an arithmetic operator has one floating-point operand and one integer operand, however, the integer will be converted to floating point before the operation is done. | ||
| + | |||
| + | ==== PRECEDENCE ==== | ||
| + | |||
| + | - != | ||
| + | - = | ||
| + | |||
| + | ==== LOGICAL OPERATORS ==== | ||
| + | |||
| + | * && - AND | ||
| + | * || - OR | ||
| + | * ! - NOT | ||
| + | |||
| + | **True** is anything but 0, e.g. | ||
| + | <code c> | ||
| + | uint8_t a = 4; | ||
| + | uint8_t b = 8; | ||
| + | uint8_t c = 0; | ||
| + | |||
| + | c = a && b; // c == 1 | ||
| + | </ | ||
| + | |||
| + | ==== BITWISE OPERATORS ==== | ||
| + | |||
| + | * & - bitwise AND (usually used to test or clear bits) | ||
| + | * | - bitwise OR (usually used to set bits) | ||
| + | * ~ - bitwise NOT (unary operator, usually used to clear bits) | ||
| + | * ^ - XOR (usually used to toggle bits) | ||
| + | |||
| + | <code c> | ||
| + | a = ~c; // bitwise unary NOT | ||
| + | </ | ||
| + | |||
| + | ==== BITWISE SHIFT === | ||
| + | |||
| + | * >> - a value will be divided by 2 for each right shift | ||
| + | * << - a value will be multiplied by 2 for each left shift | ||
| + | |||
| + | Example clearing the 4th bit with a bitwise shift operator and negation: | ||
| + | <code c> | ||
| + | data = data & | ||
| + | </ | ||
| + | |||
| + | Example bit extraction for bits [14:9]. The algorithm: | ||
| + | - Shift the portion to the right, until it touches the LSB | ||
| + | - Mask the value to extract only 6 bits [5:0] | ||
| + | |||
| + | <code c> | ||
| + | data = data >> 9; | ||
| + | data &=63; | ||
| + | </ | ||
| + | |||
| + | ==== LOOPING ==== | ||
| + | |||
| + | WHILE | ||
| + | <code c> | ||
| + | while(expression) // repeat execution of code inside the loop body until expression evaluates to 0 | ||
| + | { | ||
| + | statemen1; | ||
| + | } | ||
| + | </ | ||
| + | |||
embedded/c.1757601867.txt.gz · Last modified: by v1ctor
