From 25afb5e4e04f62dadbde0898c4f971d925a3eb2e Mon Sep 17 00:00:00 2001 From: Jens True Date: Thu, 25 Jun 2020 22:43:14 +0200 Subject: [PATCH] First step for a bit manipulation page --- content/post/bit-magic/index.md | 53 +++++++++++++++++++++++++++++++++ themes/academic | 2 +- 2 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 content/post/bit-magic/index.md diff --git a/content/post/bit-magic/index.md b/content/post/bit-magic/index.md new file mode 100644 index 0000000..bad1559 --- /dev/null +++ b/content/post/bit-magic/index.md @@ -0,0 +1,53 @@ +--- +# Documentation: https://sourcethemes.com/academic/docs/managing-content/ + +title: "Bit magic in C (and C++)" +subtitle: "" +summary: "" +authors: [] +tags: [] +categories: [] +date: 2020-06-13T19:01:19+02:00 +lastmod: 2020-06-13T19:01:19+02:00 +featured: false +draft: true + +# Featured image +# To use, add an image named `featured.jpg/png` to your page's folder. +# Focal points: Smart, Center, TopLeft, Top, TopRight, Left, Right, BottomLeft, Bottom, BottomRight. +image: + caption: "" + focal_point: "" + preview_only: false + +# Projects (optional). +# Associate this post with one or more of your projects. +# Simply enter your project's folder or file name without extension. +# E.g. `projects = ["internal-project"]` references `content/project/deep-learning/index.md`. +# Otherwise, set `projects = []`. +projects: [] +--- + +# Set a bit +```c +// Set one bit high at position "bit" in input and store to output +output = input | (1 << bit); +// Shorthand +variable |= (1 << bit); +``` + +# Clear a bit +```c +// Clear one bit high at position "bit" in input and store to output +output = input & ~(1 << bit); +// Shorthand +variable &= ~(1 << bit); +``` + +# Toggle a bit +```c +// Clear one bit high at position "bit" in input and store to output +output = x ^ (1 << bit); +// Shorthand +variable ^= (1 << bit); +``` \ No newline at end of file diff --git a/themes/academic b/themes/academic index ff252a6..8d75e9e 160000 --- a/themes/academic +++ b/themes/academic @@ -1 +1 @@ -Subproject commit ff252a6a744bf807cbf21c997248fee0ccefe41d +Subproject commit 8d75e9e27a763876b452323132fc8a1eb28bf034