Created by David Wickes / gypsydave5
true && false == false
5 && 2 == 2
'Level' && 'Up' == 'Up'
true || false == true
5 || 2 == 5
'Level' || 'Up' == 'Level'
Why `||` ? Why && ?
What about | and & ?
2.to_s(2) # => "010" 5.to_s(2) # => "101" (5 & 2).to_s(2) # => "000"
AKA '0'
2.to_s(2) # => "010" 5.to_s(2) # => "101" (5 | 2).to_s(2) # => "111"
AKA '7'
`^` - XOR
`<<` - BITSHIFT LEFT
`>>` - BITSHIFT RIGHT
7.to_s(2) # => "111" 4.to_s(2) # => "100" (5 ^ 2).to_s(2) # => "011"
7.to_s(2) # => "0111" (7 << 1).to_s(2) # => "1110"
AKA 14
4.to_s(2) # => "100" (4 >> 2).to_s(2) # => "001"
AKA 2
`~` - NOT
(AKA BITFLIP)
Write a test to show a number is a power of 2.
Show your working.
def iterate_power_of_two?(number) counter = 2 while number > counter do counter*=2 end return counter == number end
def perfect_power_of_two?(number) number & (number - 1) == 0 end
Write a test to show a directory can only be accessed by its owner.
Screw the working
it 'can only be accessed by its owner' do permissions = File.stat(folder).mode expect(permissions & 0000100).to eq(64) expect(permissions & 0000010).to eq(0) expect(permissions & 0000001).to eq(0) end