Encode-decode ruby

Páginas: 4 (870 palabras) Publicado: 29 de marzo de 2011
class EDMethod
def verifyEncodingStream(stream)
if /[^0,1]/.match(stream)
return nil
else
return 1
end
end
def encode (stream)
puts "Encode functionmust be implemented"
end
def decode (stream)
puts "Decode function must be implemented"
end
end

class NRZL < EDMethod
def verifyDecodingStream(stream)
if/[^+,-]/.match(stream)
return nil
else
return 1
end
end
def encode (stream)
puts "The NRZL encoding for the bit stream is: "
stream.length.times do |num|
ifstream[num..num].to_i==0
putc '-'
elsif stream[num..num].to_i==1
putc '+'
end
end
end
def decode (stream)
puts "The NRZL decoding for the signal is: "stream.length.times do |num|
if stream[num..num]=='-'
putc '0'
elsif stream[num..num]=='+'
putc '1'
end
end
end
end

class NRZI < EDMethod
defverifyDecodingStream(stream)
if /[^+,-]/.match(stream)
return nil
else
return 1
end
end
def encode (stream)
puts "The NRZI encoding for the bit stream is: "
ant='-'
stream.length.times do |num|
if stream[num..num] =='1'
if ant == '+'
ant = '-'
putc '-'
elsif ant == '-'
ant = '+'
putc'+'
end
elsif stream[num..num] =='0'
if ant == '+'
ant = '+'
putc '+'
elsif ant == '-'
ant = '-'
putc '-'
endend
end
end
def decode (stream)
puts "The NRZI decoding for the signal is: "
ant = '-'
stream.length.times do |num|
if stream[num..num]==ant
putc'0'
else
putc '1'
end
ant = stream[num..num]
end
end
end

class AMI < EDMethod
def verifyDecodingStream(stream)
if /[^\+,\-,0]/.match(stream)...
Leer documento completo

Regístrate para leer el documento completo.

Estos documentos también te pueden resultar útiles

  • Decode
  • Decoder
  • decode
  • decoder
  • Encoder
  • encoder
  • ruby
  • Ruby

Conviértase en miembro formal de Buenas Tareas

INSCRÍBETE - ES GRATIS