Binary Translator

By trance on Sep 11, 2004

This snipped translates $chr's to binary code. It's very simple to use it, just $bin(). It translates $chr(32) also, so if you wanna traslate for ex. "Hello World." again just - $bin(Hello World.). $bin() will return the binary code of all $chr's in $1-. Hope you can use it for something.

;Binary Translator
;By: trance @ hawkee.com
;E-mail: trance@trakia.net
;Syntax: $bin()

alias bin {
  if ($1) {
    set %chars $len($1-)
    var %asc
    while (%chars >= 1 ) {
      set %asc $+(%asc,$chr(32),$asc($right($left($1-,%chars),1)))
      dec %chars
    }
    return $parse_asc(%asc)
  }
}
alias parse_asc {
  if ($1) {
    var %bin
    set %tokens $numtok($1-,32)
    while ( %tokens >= 1 ) {
      set %asc_chr $gettok($1-,%tokens,32)
      var %temp.bin.chr
      while ( $calc(%asc_chr / 2 ) != 0.5 ) {
        if ($calc(%asc_chr / 2 ) != $round($calc(%asc_chr / 2 ),0)) { 
          set %temp.bin.chr $+(%temp.bin.chr,1)
          set %asc_chr $calc($calc(%asc_chr - 1) / 2)
        }
        else { 
          set %temp.bin.chr $+(%temp.bin.chr,0)
          set %asc_chr $calc(%asc_chr / 2)
        }
      }
      set %bin $+(%bin,$chr(32),%temp.bin.chr)
      dec %tokens
    }
    return %bin
  }
}

Comments

Sign in to comment.
Bry`   -  Dec 18, 2009

the number 5 is really character 53 in ascii, which is 00110101 in binary

 Respond  
Danielplanto   -  Dec 29, 2008

ok so HOW do you use it exactly?

 Respond  
log2   -  Mar 13, 2005

is that what you got... cuz I calcualted it in my head and got 5 = 00101 not 10101 that would be 21 not 5... how did you get 5?

 Respond  
trance   -  Sep 11, 2004

the binary code for num 5 is 10101

 Respond  
trance   -  Sep 11, 2004

$bin() is a identificator, not a command. Use //echo = $bin() to view the returned binary code.

 Respond  
LIQUID_NiTrO   -  Sep 11, 2004

Doesn\'t appear to work...I type $bin(5) in the box and hit tab and nothing happens

 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.