MATLAB: Convert binary string into hex binary to hex numbers i need to convert this binary string [ '0101010011101010'] into hex or decimal but in 2^4 mean (i need to convert 4bit by 4bit) not all number Best Answer lookup = containers.Map(cellstr(dec2bin(0:15,4)),cellstr(dec2hex(0:15)));binary_string = '0101010011101010';output = cellfun(@(S) lookup(S), cellstr(reshape(binary_string, 4, []).')).';This code assumes that binary_string is a multiple of 4 bits.This is definitely not the only way to do the task. It has the advantage, though, that it does not need to convert the inputs into numeric form.Another way:output = cell2mat(regexprep(cellstr(reshape(binary_string,4,[]).'), cellstr(dec2bin(0:15,4)), cellstr(dec2hex(0:15)),'once').'); Related SolutionsMATLAB: How to convert a string to binary and then from the binary back to string binary = reshape(dec2bin(s, 8).'-'0',1,[])str = char(bin2dec(reshape(char(binary+'0'), 8,[]).')) MATLAB: Covert 128 binary string into hex decimal b = your binary digits vectord = [8 4 2 1]*reshape(b,4,[]);h = sprintf('%x',d); Related QuestionHow to convert an array of binary values into the corresponding decimal number within MATLABConversion of binary to decimalHow to add leading zeros to a number in Hex formatConvert binary to hexHow to separate first 8 digits in binary format and convert them to the hex
Best Answer