From e71f1f2c4df216677d62043070e40aa31bf4f6c3 Mon Sep 17 00:00:00 2001 From: Jens True Date: Sun, 2 Aug 2020 14:34:35 +0200 Subject: [PATCH] More bitmagic. Theme update --- content/post/bit-magic/index.md | 29 ++++++++++++++++++++++++++++- themes/academic | 2 +- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/content/post/bit-magic/index.md b/content/post/bit-magic/index.md index 613cad3..1a669c4 100644 --- a/content/post/bit-magic/index.md +++ b/content/post/bit-magic/index.md @@ -10,7 +10,7 @@ categories: [] date: 2020-06-13T19:01:19+02:00 lastmod: 2020-06-13T19:01:19+02:00 featured: false -draft: true +draft: false # Featured image # To use, add an image named `featured.jpg/png` to your page's folder. @@ -57,4 +57,31 @@ output = x ^ (1 << bit); variable ^= (1 << bit); // Multiple bits variable ^= (0b101 << bit); +``` + +# Math +```c +// Division using bitshift +output = input >> 1; // Divide by 2 +output = input >> 2; // Divide by 4 +output = input >> 3; // Divide by 8 +// Multiply using bitshifting +output = input << 1; // Multiply by 2 +output = input << 2; // Multiply by 4 +output = input << 3; // Multiply by 8 +``` + +# Set X number of bits high. +```c +output = (0b1 << X) -1; +``` + +# Miccelean +```c +// Check if number is ODD +if( (num & 1) == 1) {}; +// Flip signed integer +num = ~num + 1; +// Power of two +num > 0 && (num & (num - 1)) == 0; ``` \ No newline at end of file diff --git a/themes/academic b/themes/academic index c4f0317..6bf2822 160000 --- a/themes/academic +++ b/themes/academic @@ -1 +1 @@ -Subproject commit c4f0317cdf5b2197bb42e793b151a246534b7b48 +Subproject commit 6bf282275adcab3bd96df71bc75bf32fb09b1106