User:Fabien Labeyrie/Bit Shifting: Difference between revisions
(Created page with "__NOTOC__ __NOEDITSECTION__ ==<span style="color:#00FF00">Bit Shifting : learning how to count like a machine</span>== The idea is to work with inputs and outputs of Arduino to m...") |
No edit summary |
||
Line 1: | Line 1: | ||
__NOTOC__ | __NOTOC__ | ||
__NOEDITSECTION__ | __NOEDITSECTION__ | ||
==<span style="color:#00FF00">Bit Shifting : | ==<span style="color:#00FF00">Bit Shifting : how i learned to stop worrying and love binary numbers</span>== | ||
Here is how to deal with binary numbers when you are programming on an old computer (Basic V 2.0 on Commodore 64) or when you are configuring internal parameters on your arduino board. Thanks to Mr. Stock who made this nightmare look nearly simple. | |||
<br /> | <br /> | ||
== | ==What is << (bit shifting) ?== | ||
In the binary numeral system, everything looks like 0110010100010100111... <br /> | |||
A bit shift consists in moving one or several digits in a line of 0110010100010100111... <br /> | |||
====Examples==== | |||
<br /> | <br /> | ||
= | 1 << 3 | ||
<pre> | |||
1 = 0001 in the binary numeral system | |||
1 << 3 means we are gonna move the value 1, to the left <<, 3 times. | |||
1 << 3 : 0001 -> 0010 -> 0100 -> 1000 | |||
1st move 2nd move 3rd move | |||
< | 1 << 3 = 1000 and 1000 in the binary numeral system = 8 | ||
</pre> | |||
7 << 5 | |||
<pre> | |||
7 = 00000111 | |||
7 << 5 : 0000 0111 -> 0000 1110 -> 0001 1100 -> 0011 1000 -> 0111 0000 -> 1110 0000 | |||
7 << 5 = 1110000 in the binary numeral system = 224 | |||
</pre> | |||
<br /> | |||
=The best is yet to come= | |||
==The nibble== | |||
==Big endian Vs little endian== | |||
==Logical operations== | |||
==Bits and modulo== | |||
Revision as of 01:00, 24 March 2011
Bit Shifting : how i learned to stop worrying and love binary numbers
Here is how to deal with binary numbers when you are programming on an old computer (Basic V 2.0 on Commodore 64) or when you are configuring internal parameters on your arduino board. Thanks to Mr. Stock who made this nightmare look nearly simple.
What is << (bit shifting) ?
In the binary numeral system, everything looks like 0110010100010100111...
A bit shift consists in moving one or several digits in a line of 0110010100010100111...
Examples
1 << 3
1 = 0001 in the binary numeral system 1 << 3 means we are gonna move the value 1, to the left <<, 3 times. 1 << 3 : 0001 -> 0010 -> 0100 -> 1000 1st move 2nd move 3rd move 1 << 3 = 1000 and 1000 in the binary numeral system = 8
7 << 5
7 = 00000111 7 << 5 : 0000 0111 -> 0000 1110 -> 0001 1100 -> 0011 1000 -> 0111 0000 -> 1110 0000 7 << 5 = 1110000 in the binary numeral system = 224