Re: conversion
- Posted by Pete Eberlein <xseal at HARBORSIDE.COM> Aug 01, 1997
- 840 views
klepto wrote: > Yes, binary code. What I was thinking, was inputing a sequence of binary > codes and having the app convert it to text, and also the other way around, > input text, and have the app convert it to binary. > Thanks :) Here's two functions that do this: ---- code begins ---- include machine.e function text_to_binary(sequence text) sequence binary binary = {} for i = 1 to length(text) do binary = binary & int_to_bits(text[i], 8) end for return binary end function function binary_to_text(sequence binary) sequence text text = {} for i = 1 to length(binary) by 8 do text = text & bits_to_int(binary[i..i+7]) end for return text end function ---- code ends ---- -- _____ _____ _____ ________ /\ \ /\ \ /\ \ / \ \ / \____\ / \____\ / \____\ / _ \____\ / / ___/_ / /____/ / / ___/_ / / \ |____|/ / /\____\ / \ \ / / /\____\ \ \_/ / / \ \/ / ___/_\ \ \ \ \/ / ___/_ \ /____/ \ / /\ \\/\ \ \ \ / /\ \ \ \ \ \ \/ \____\ \ \ \ \ \/ \____\ \ \ \ \ / / \ \____\ \ / / \ \____\ \ / / \ / / \ / / \ / / \ / / \/____/ \ / / \/____/ \/____/ \/____/