Skip to content

Instantly share code, notes, and snippets.

@madex
madex / softi2c.c
Last active August 29, 2015 14:07
universal software i2c for microcontrollers
// example for xmega256d3
// bit delay
static void delay(void) {
__no_operation();
__no_operation();
__no_operation();
__no_operation();
__no_operation();
__no_operation();
@madex
madex / itoaFixedWidth.c
Last active August 26, 2021 05:38
Fast 32bit signed itoa without division and with fixed width (base 10) filled up with spaces.
char *itoaFixedWidth(int32_t zahl) {
static uint32_t subtractors[] = {1000000000, 100000000, 10000000, 1000000,
100000, 10000, 1000, 100, 10, 1};
static char string[12];
char n, *str = string, sign = zahl < 0 ? '-' : ' ';
uint32_t *sub = subtractors;
uint32_t u = zahl < 0 ? (uint32_t) -zahl : (uint32_t) zahl;
uint8_t i = 10;
*str++ = ' ';
while (i > 1 && u < *sub) {
@madex
madex / sudoku.c
Last active August 29, 2015 14:07
my obfuscated sudoku solver
#include <stdio.h>
#define _ 0
#define S(x) x,
#define D(x) x x x
#define L(x) D(S(x))
#define R(x) D(D(S(x)))
#define E(f,x) f(x)f(x+1)f(x+2)
char sudoku[] = {
1, _, _, _, _, 7, _, 9, _,
_, 3, _, _, 2, _, _, _, 8,