Cody

Problem 2046. Convert binary numbers to hexadecimal numbers

Solution 2890547

Submitted on 29 Aug 2020 by Atsushi Ueno
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   Pass
x = [1 1 1 1 0 0 0 0 1 1 1 0 0 0 0 1] ; y_correct = 'F0 E1'; assert(isequal(bin2hex(x),y_correct));

ans = 4×1 char array 'F' '0' 'E' '1' ans = 2×2 char array 'F0' 'E1' ans = 'F0 E1'

2   Pass
x = ones(1,80); y_correct = 'FF FF FF FF FF FF FF FF FF FF'; assert(isequal(bin2hex(x),y_correct));

ans = 20×1 char array 'F' 'F' 'F' 'F' 'F' 'F' 'F' 'F' 'F' 'F' 'F' 'F' 'F' 'F' 'F' 'F' 'F' 'F' 'F' 'F' ans = 10×2 char array 'FF' 'FF' 'FF' 'FF' 'FF' 'FF' 'FF' 'FF' 'FF' 'FF' ans = 'FF FF FF FF FF FF FF FF FF FF'

3   Pass
x = zeros(1,8); y_correct = '00'; assert(isequal(bin2hex(x),y_correct));

ans = 2×1 char array '0' '0' ans = '00' ans = '00'

4   Pass
x = '1 0 0 1 1 1 1 0 0 1 1 0 1 0 1 1 1 1 1 0 0 0 1 0 1 0 0 1 1 0 1 0'; y_correct = '9E 6B E2 9A'; assert(isequal(bin2hex(x),y_correct));

ans = 8×1 char array '9' 'E' '6' 'B' 'E' '2' '9' 'A' ans = 4×2 char array '9E' '6B' 'E2' '9A' ans = '9E 6B E2 9A'

Suggested Problems

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!