%% Bytes, Bits, and Character Representation
% Tim Placek - CHEN 3600 - Computer-Aided Chemical Engineering
% Spring 2012
%
format compact, format short g, clear, clc
%% Available symbols:
% Base-10 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
% Base-2 0, 1
% Base-16 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F
%% Building Numbers
% 103[10] = 1(10^2) + 0(10^1) + 3(10^0) = 103[base-10]
% 10010[2] = 1(2^4) + 0(2^3) + 0(2^2) + 1(2^1) + 0(2^0) = 18[base10]
% = 1(16) + 0(8) + 0(4) + 1(2) + 0(1) = 18[base10]
%% Counting in base10 and base16 and base2
format compact, format short g, clear, clc
fprintf(' k(base10) k(base(16) k(base2)\n');
for i = 1:16
k = i-1;
h = dec2hex(k);
m = dec2bin(k);
fprintf(' %d %s %s\n', k, h, m);
end
%% Characters in base10 and hex (base16)
format compact, format short g, clear, clc
fprintf(' k(base10) k(base16) k(base2) k(character)\n');
for k = 32:127
h = dec2hex(k);
n = dec2bin(k);
m = char(k);
fprintf(' %d %s %s %s\n', k, h, n, m);
end
%% Numbers from characters
format compact, format short g, clear, clc
fprintf(' character k(base10)\n');
for k = 32:127
m = char(k);
n = num2str(m);
fprintf(' %s %d \n', m, n);
end
%% Working with strings
format compact, format short g, clear, clc
breed = 'Pembroke Welsh Corgi';
% Convert any uppercase to lowercase
for k = 1:length(breed)
if (breed(k)>='A' & breed(k) <= 'Z')
breed(k)=breed(k)+32;
end
end
breed
% Raise the 3rd letter by one character
breed(3)=breed(3)+1;
breed
%% So what is a Welsh Corgi???
im = imread('PembrokeLucy2.jpg');
imshow(im);
pause(5)
im = rgb2gray(im);
imshow(im);