Cody

# Problem 832. Convert single-precision floating-point number to binary representation

Solution 1983913

Submitted on 21 Oct 2019
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

### Test Suite

Test Status Code Input and Output
1   Fail
x = single(1.25); y_correct = '00111111101000000000000000000000'; assert(isequal(single2bin(x),y_correct))

Unrecognized function or variable 'hex'. Error in single2bin>@(x)find(hex==x)-1 (line 4) nums = cellfun(@(x) find(hex == x) - 1, hc); Error in single2bin (line 4) nums = cellfun(@(x) find(hex == x) - 1, hc); Error in Test1 (line 3) assert(isequal(single2bin(x),y_correct))

2   Fail
x = realmax('single'); y_correct = '01111111011111111111111111111111'; assert(isequal(single2bin(x),y_correct))

Unrecognized function or variable 'hex'. Error in single2bin>@(x)find(hex==x)-1 (line 4) nums = cellfun(@(x) find(hex == x) - 1, hc); Error in single2bin (line 4) nums = cellfun(@(x) find(hex == x) - 1, hc); Error in Test2 (line 3) assert(isequal(single2bin(x),y_correct))

3   Fail
x = realmin('single'); y_correct = '00000000100000000000000000000000'; assert(isequal(single2bin(x),y_correct))

Unrecognized function or variable 'hex'. Error in single2bin>@(x)find(hex==x)-1 (line 4) nums = cellfun(@(x) find(hex == x) - 1, hc); Error in single2bin (line 4) nums = cellfun(@(x) find(hex == x) - 1, hc); Error in Test3 (line 3) assert(isequal(single2bin(x),y_correct))

4   Fail
x = single(-1.625e21); y_correct = '11100010101100000010111011001111'; assert(isequal(single2bin(x),y_correct))

Unrecognized function or variable 'hex'. Error in single2bin>@(x)find(hex==x)-1 (line 4) nums = cellfun(@(x) find(hex == x) - 1, hc); Error in single2bin (line 4) nums = cellfun(@(x) find(hex == x) - 1, hc); Error in Test4 (line 3) assert(isequal(single2bin(x),y_correct))