i need an matlab coding for convert a binary value into hexadecimal value? here am having a code for hexa to binary, now i need the decryption process (i.e.,)binary to hexadecimal values.

8 views (last 30 days)
clc;
close all;
clear all;
tic;
col = 'C0C0C080008000ff00ff00ffFF6347FFA5009ACD32FFD700FFA500BDB76B9ACD32F0E68CBDB76BDAA520B8860BFFA5009ACD32FFA072FFD700FFA500BDB76Bff0000ff00ff0000ff8000808000800000ffC0C0C0';
n6 = length(col);
c6 = [];
for i = 1:n6
pt6 = col(i);
if pt6 == '0'
c6 = [c6 '0000'];
elseif pt6 == '1'
c6 = [c6 '0001'];
elseif pt6 == '2'
c6 = [c6 '0010'];
elseif pt6 == '3'
c6 = [c6 '0011'];
elseif pt6 == '4'
c6 = [c6 '0100'];
elseif pt6 == '5'
c6 = [c6 '0101'];
elseif pt6 == '6'
c6 = [c6 '0110'];
elseif pt6 == '7'
c6 = [c6 '0111'];
elseif pt6 == '8'
c6 = [c6 '1000'];
elseif pt6 == '9'
c6 = [c6 '1001'];
elseif pt6 == 'A'| pt6 == 'a'
c6 = [c6 '1010'];
elseif pt6 == 'B'| pt6 == 'b'
c6 = [c6 '1011'];
elseif pt6 == 'C'| pt6 == 'c'
c6 = [c6 '1100'];
elseif pt6 == 'D'| pt6 == 'd'
c6 = [c6 '1101'];
elseif pt6 == 'E'| pt6 == 'e'
c6 = [c6 '1110'];
elseif pt6 == 'F'| pt6 == 'f'
c6 = [c6 '1111'];
end
end
toc;

Answers (1)

Stephen23
Stephen23 on 16 Feb 2016
Edited: Stephen23 on 16 Feb 2016
col = 'C0C0C080008000ff00ff00ffFF6347FFA5009ACD32FFD700FFA500BDB76B9ACD32F0E68CBDB76BDAA520B8860BFFA5009ACD32FFA072FFD700FFA500BDB76Bff0000ff00ff0000ff8000808000800000ffC0C0C0';
% Convert hex to binary:
B = dec2bin(sscanf(col,'%1x')).';
B = B(:).';
% Convert binary back to hex:
H = dec2hex(bin2dec(reshape(B,4,[]).'));
H = H(:).';
% Confirm output hex is same as input hex:
strcmpi(col,H)

Categories

Find more on App Building in Help Center and File Exchange

Tags

No tags entered yet.

Community Treasure Hunt

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

Start Hunting!