Binary to text

By log2 on Mar 13, 2005

This is what I've been slaving over for the past 5 hours.. A person enters a binary value and this little beuty converts the binary entered into a character! pretty easy to use, type !b-t to use it. but the downside of it is that right now it only converts one letter at a time :(

; Type !b-t then a binary number to try this script out!
; L0g2 St3w
; http://4d.freeunixhost.com/
on *:TEXT:*:#log2: {
  if ($1 == !b-t) {
; errors syntax, these show!
    if ($2 == $null) {
      msg $chan Enter some binary!
    }
    if ($len($2) != 8) {
      msg $chan Have you ever seen Binary to Text conversion? you need 8 numbers between 0-1!
      halt
    }
    if ($regex($2,/[a-zA-Z_]/) >= 1) {
      msg $chan Binary doesn't have letters!
      halt
    }
    if ($regex($2,/[2-9]/) >= 1) {
      msg $chan You fool! Binary ONLY contains 1's and 0's
      halt
    }
    else {
      set %bin.text $2
      set %bin.inc 1
      while (%bin.inc < 9) {
        set %bin. $+ %bin.inc $mid($2,%bin.inc,1)
        inc %bin.inc
      }
      conversion
    }
  }
}
; Converts the binary to numbers
alias conversion {
  if (%bin.1 == 1) {
    %bin.1 = 128
  }
  else {
    %bin.1 = 0
  }
  if (%bin.2 == 1) {
    %bin.2 = 64
  }
  else {
    %bin.2 = 0
  }
  if (%bin.3 == 1) {
    %bin.3 = 32
  }
  else {
    %bin.3 = 0
  }
  if (%bin.4 == 1) {
    %bin.4 = 16
  }
  else {
    %bin.4 = 0
  }
  if (%bin.5 == 1) {
    %bin.5 = 8
  }
  else {
    %bin.5 = 0
  }
  if (%bin.6 == 1) {
    %bin.6 = 4
  }
  else {
    %bin.6 = 0
  }
  if (%bin.7 == 1) {
    %bin.7 = 2
  }
  else {
    %bin.7 = 0
  }
  if (%bin.8 == 1) {
    %bin.8 = 1
  }
  else {
    %bin.8 = 0
  }
;Calculates and changes the binary to a letter
  %bin.tot = $calc(%bin.1 + %bin.2 + %bin.3 + %bin.4 + %bin.5 + %bin.6 + %bin.7 + %bin.8)
  msg # I did it! I got it! The ascii value of %bin.text is: $chr(%bin.tot)
  unset bin.*
}

Comments

Sign in to comment.
tye   -  Mar 13, 2005

You can use $base to convert from binary to decimal. Example: $base(101,2,10) = 5 (the 101 is the binary number, 2 is the in \'base\', 10 is the out \'base\'. 2 = binary, 10 = decimal, 16 = hexidecimal)

 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.