Skip to content

Instantly share code, notes, and snippets.

@JeffIrwin
Created January 23, 2020 01:54
Show Gist options
  • Save JeffIrwin/6634c8e1ffee5611ceabe41acab81fed to your computer and use it in GitHub Desktop.
Save JeffIrwin/6634c8e1ffee5611ceabe41acab81fed to your computer and use it in GitHub Desktop.
Text to/from binary conversion in Scilab
clear
clc
xdel(winsid())
asc = 'send help'
//==============================================================================
bin = ''
for k = 1: length(asc)
ik = ascii(part(asc, k: k))
bin = bin + dec2bin(ik, 8) + ' '
end
mprintf('%s', bin)
clear
clc
xdel(winsid())
bin = ' 01110011 01100101 01101110 01100100 00100000 01101110 01110101 01100100 01100101 01110011 '
//==============================================================================
binf = ''
for k = 1: length(bin)
b = part(bin, k: k)
if (b == '0' || b == '1')
// Filter out whitespace (line breaks, etc.)
binf = binf + b
end
end
for k = 1: 8: length(binf)
// mprintf('%d\n', k)
ik = bin2dec(part(binf, k: k+7))
a = ascii(ik)
mprintf('%s', a)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment