diff --git a/src/main/java/LightSwitcher.java b/src/main/java/LightSwitcher.java index 4499c39..66908f8 100644 --- a/src/main/java/LightSwitcher.java +++ b/src/main/java/LightSwitcher.java @@ -8,11 +8,14 @@ */ public class LightSwitcher { + + /** * Take a given input of switches, and the switches to turn on, and return the new state of the switches. * NOTE: If the initial state of a switch is already turned on, do not turn it off. */ public static int turnOnSwitches(int switches, int switchesToTurnOn) { + return switches | switchesToTurnOn; } @@ -21,7 +24,9 @@ public static int turnOnSwitches(int switches, int switchesToTurnOn) { * Remember to use bit notation (0bxxxxxxxx) and a bit operator. */ public static int turnOnAllSwitches(int switches) { - + + return 0b11111111 | switches; + } /** @@ -30,7 +35,9 @@ public static int turnOnAllSwitches(int switches) { * And a '1' in a position in 'switchesToTurnOff' means to turn that switch to off. */ public static int turnOffSwitches(int switches, int switchesToTurnOff) { - + + return switches & ~switchesToTurnOff; + } /** @@ -38,7 +45,9 @@ public static int turnOffSwitches(int switches, int switchesToTurnOff) { * Remember to use bit notation and a bit operator. */ public static int turnOffAllSwitches(int switches) { - + + return 0b00000000 & switches; + } /** @@ -47,7 +56,8 @@ public static int turnOffAllSwitches(int switches) { * I.E switches = 1 0 1 and switchesToFlip = 1 1 0 should return 0 1 1. */ public static int flipSwitches(int switches, int switchesToFlip) { - + return switches ^ switchesToFlip; + } /** @@ -55,7 +65,8 @@ public static int flipSwitches(int switches, int switchesToFlip) { * NOTE: An integer has more than 8 bits, so find a way to only return the rightmost 8 bits. */ public static int flipAllSwitches(int switches) { - + return ~switches & 0b000000000000000011111111 ; + } /** @@ -64,14 +75,17 @@ public static int flipAllSwitches(int switches) { * So, a byte reads 76543210 */ public static int getSwitchPositionAt(int switches, int position) { - + + return switches >>> position & 0b000000000000000000000001; + } /** * Move all the the bits to the right `count` places. */ public static int moveRightBy(int switches, int count) { - + return switches >> count; + } /** @@ -79,7 +93,7 @@ public static int moveRightBy(int switches, int count) { * NOTE: An integer has more than 8 bits, so find a way to only return the rightmost 8 bits. */ public static int moveLeftBy(int switches, int count){ - + return switches << count & 0b000000000000000011111111 ; } /**