Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Solution 238804

Submitted on 1 May 2013 by Claudio Gelmi

Correct

11Size
This is the leading solution.
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

Test Suite

Test
Code Input and Output
1
Pass
 
%%
x = 2^5;
y_correct = true;
assert( isequal(on_bit_boundary(x),y_correct) )
x = 2^5 - 5;
y_correct = false;
assert( isequal(on_bit_boundary(x),y_correct) )
x = 127
y_correct = true;
assert( isequal(on_bit_boundary(x),y_correct) )
x = 1023
assert( isequal(on_bit_boundary(x),y_correct) )
y_correct = false;
x = 501
assert( isequal(on_bit_boundary(x),y_correct) )
v = 2*(rand(1,10) > 0.5)-1;
for i =2:10
   assert( on_bit_boundary( 2^i + v(i)) == (v(i) < 0 ) )
end
y =
     1
y =
     0
x =
   127
y =
     1
x =
        1023
y =
     1
x =
   501
y =
     0
y =
     0
y =
     0
y =
     1
y =
     1
y =
     1
y =
     1
y =
     0
y =
     1
y =
     0