Last active
August 29, 2015 14:15
-
-
Save pcon/d92a7d16cd5998d49d88 to your computer and use it in GitHub Desktop.
Bitmath
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
┌─┬───────────── Not used. | |
│ │ ┌─────────── Bottom Ranged | |
│ │ │ ┌───────── Bottom Melee | |
│ │ │ │ ┌─────── Middle Ranged | |
│ │ │ │ │ ┌───── Middle Melee | |
│ │ │ │ │ │ ┌─── Top Ranged | |
│ │ │ │ │ │ │ ┌─ Top Melee | |
│ │ │ │ │ │ │ │ | |
0 0 0 0 0 0 0 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Integer bottomRanged = 1; | |
Integer bottomMelee = 1; | |
Integer middleRanged = 0; | |
Integer middleMelee = 1; | |
Integer topRanged = 0; | |
Integer topMelee = 1; | |
Integer value = 0; // Binary 00000000 | |
value += bottomRanged; // Binary 00000001 | |
value <<= 1; // Binary 00000010 | |
value += bottomMelee; // Binary 00000011 | |
value <<= 1; // Binary 00000110 | |
value += middleRanged; // Binary 00000110 | |
value <<= 1; // Binary 00001100 | |
value += middleMelee; // Binary 00001101 | |
value <<= 1; // Binary 00011010 | |
value += topRanged; // Binary 00011010 | |
value <<= 1; // Binary 00110100 | |
value += topMelee; // Binary 00110101 | |
// Integer 53 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Integer value = 53; | |
// Binary 00110101 | |
Integer BOTTOM_MASK_RANGED = 32; // Binary 00100000 | |
Integer BOTTOM_OFFSET_RANGED = 5; | |
Integer BOTTOM_MASK_MELEE = 16; // Binary 00010000 | |
Integer BOTTOM_OFFSET_MELEE = 4; | |
Integer MIDDLE_MASK_RANGED = 8; // Binary 00001000 | |
Integer MIDDLE_OFFSET_RANGED = 3; | |
Integer MIDDLE_MASK_MELEE = 4; // Binary 00000100 | |
Integer MIDDLE_OFFSET_MELEE = 2; | |
Integer TOP_MASK_RANGED = 2; // Binary 00000010 | |
Integer TOP_OFFSET_RANGED = 1; | |
Integer TOP_MASK_MELEE = 1; // Binary 00000001 | |
Integer TOP_OFFSET_MELEE = 0; | |
Integer bottomRanged = (value & BOTTOM_MASK_RANGED) >> BOTTOM_OFFSET_RANGED;// 1 | |
Integer bottomMelee = (value & BOTTOM_MASK_MELEE) >> BOTTOM_OFFSET_MELEE; // 1 | |
Integer middleRanged = (value & MIDDLE_MASK_RANGED) >> MIDDLE_OFFSET_RANGED;// 0 | |
Integer middleMelee = (value & MIDDLE_MASK_MELEE) >> MIDDLE_OFFSET_MELEE; // 1 | |
Integer topRanged = (value & TOP_MASK_RANGED) >> TOP_OFFSET_RANGED;// 0 | |
Integer topMelee = (value & TOP_MASK_MELEE) >> TOP_OFFSET_MELEE; // 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Integer value = 132; | |
// Binary 10000100 | |
Integer PLAYER_MASK = 7; | |
// Binary 00000111 | |
Integer result = value & PLAYER_MASK; | |
// Binary 00000100 | |
// Integer 4 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
┌─────────────── Team (false if Radiant, true if Dire). | |
│ ┌─┬─┬─┬─────── Not used. | |
│ │ │ │ │ ┌─┬─┬─ The position of a player within their team (0-4). | |
│ │ │ │ │ │ │ │ | |
0 0 0 0 0 0 0 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Integer value = 132; | |
// Binary 10000100 | |
Integer shift = 7; | |
Integer result = value >> shift; | |
// Binary 00000001 | |
// Integer 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment