# Complete Binary Conversion

### By log2 on Mar 29, 2005

Ok this is a script that will convert a number to binary.... a binary number to a number or a character to binary, or binary to a character.... It's very easy to use... just type help if you don't get it but the comments at the start should explain it all... enjoy!

``````; !num-bin converts a number to binary
; created by L0g2 St3w
; !chr-bin converts a character to binary
; visit http://4d.freeunixhost.com if you like this script
; !bin-num converts binary to a number
; OR TYPE !help FOR HELP!
on *:text:*:#: {
if (\$1 == !num-bin) {
if (\$regex(\$2,/[a-zA-Z_]/) >= 1) {
msg \$chan You need to enter a Number to convert to binary!
halt
}
elseif (\$2 == \$null) {
msg \$chan At least enter something...
}
if (\$len(\$2) > 10) {
msg \$chan Hold on there, you trying to flood?
}
else {
set %number \$base(\$2,10,2)
msg \$chan The binary version of: \$2 is: %number
}
}
if (\$1 == !chr-bin) {
if (\$2 == \$null) {
msg \$chan enter some text
halt
}
if (\$len(\$2) > 1) {
msg \$chan Hold on, I can only handle one letter at a time... to prevent flooding.
}
else {
%text = \$asc(\$2)
%text2 = \$base(%text,10,2)
msg \$chan The binary of: \$2 is: %text2
}
}
if (\$1 == !bin-num) {
if (\$2 == \$null) {
msg \$chan enter a binary number
halt
}
if (\$regex(\$2,/[a-zA-z_]/) >= 1) {
msg \$chan There is no text in numbers
halt
}
elseif (\$regex(\$2,/[2-9]/) >= 1) {
msg \$chan \$2 is not a binary number
halt
}
if (\$len(\$2) >= 20) {
msg \$chan Ok, I believe that's flooding
}
else {
%numb = \$base(\$2,2,10)
msg \$chan The decimal version of: \$2 is: %numb
}
}
if (\$1 == !bin-chr) {
if (\$2 == \$null) {
msg \$chan enter a binary number
halt
}
if (\$len(\$2) > 8) {
msg \$chan Hold on... That's not a letter... A letter is 8 binary numbers!
}
else {
%numb = \$base(\$2,2,10)
msg \$chan The letter of: \$2 is: \$chr(%numb)
}
}
if (\$1 == !help) {
if (\$2 == binary) {
echo -a The binary system is simple... Type !bin-num to get binary to number!
echo -a Type !num-bin to get number to binary!
echo -a Type !chr-bin or !bin-chr to get the character to binary or binary to character!
echo -a If you need more help type: !help extensive
}
if (\$2 == extensive) {
echo -a Look in your status window!
echo -s START TRANSMISSION:
echo -s ------------------------------------------
echo -s Ok so you need extensive help do you?
echo -s To really understand this program we need to understand binary
echo -s Let's get started, Binary is a simple language containing 1's and 0's
echo -s 1 means true and 0 means false
echo -s The scheme for converting to decimal from binary is as follows:
echo -s 00000000 now they can either be 0's or 1's and here's what they represent:
echo -s 0=128 0=64 0=32 0=16 0=8 0=4 0=2 0=1 Do you understand that? pretty simple no?
echo -s Ok so now you know the values of each 0... if it's zero that means it's false
echo -s As I've previously stated... if it's 1 that means that number is true!
echo -s so if you see: 00000001 that equals 1, 00000010 equals 2 00000100 equals 4 and so on!
echo -s now... if you see something like: 00000011 that equals 3 because you add both the values together!
echo -s so there for 00001010 equals? 10! and 11111111 equals? 255!
echo -s If you see binary like this: 110101 that is the same as 00110101
echo -s Or if you see binary like this: 1 that is the same as 00000001!
echo -s so if a binary number starts with a zero.. that/those zero(s) does/do not count!
echo -s Ok so now you understand binary let's try those comands again!
echo -s !num-bin is binary to a number, the opposite of what I told you!
echo -s If you need an explanation of numbers to binary then type !help num-bin
echo -s Now !bin-num is what you learned up there!
echo -s !chr-bin is Character to binary, that isn't too different.
echo -s If you need help with character to binary type !help chr-bin
echo -s And the last one is !bin-chr, or binary to character!
echo -s If you need help with binary to character type !help bin-chr
echo -s ------------------------------------------
echo -s END TRANSMISSION!
}
if (\$2 == num-bin) {
echo -s START TRANSMISSION:
echo -s ------------------------------------------
echo -s Let's get started, Binary is a simple language containing 1's and 0's
echo -s 1 means true and 0 means false
echo -s The scheme for converting to decimal to binary is as follows:
echo -s 00000000 now they can either be 0's or 1's and here's what they represent:
echo -s 0=128 0=64 0=32 0=16 0=8 0=4 0=2 0=1 Do you understand that? pretty simple no?
echo -s So that's the same as before... so we know the values
echo -s There's a very easy way to do this that my computer engineering teacher taught me:
echo -s if you have the number 25 and the scheme is 00000000 then all you do is substitute in numbers:
echo -s the 6th 0 is 32... that's over the original number 25!
echo -s the 5th 0 is 16 under it so put a one there... so far we have: 00010000
echo -s the 4th 0 is 8 add it to 16(the 5th 0) if you go over 25 then it's a 0, it doesn't we're at 24!
echo -s the 3rd 0 is 4, if we add that to our value (24) we go over 25... no good make it a 0
echo -s the 2nd 0 is 2, if we add that to out value (24) we go over 25... scrap it.. make it 0
echo -s the 1st 0 is 1, add that to 24 we get 25... therefor our number is: 00011001!
echo -s ------------------------------------------
echo -s END TRANSMISSION!
}
if (\$2 == chr-bin) {
echo -s START TRANSMISSION:
echo -s ------------------------------------------
echo -s Ok you have a character, you want it to be binary, well first you need the ASCII value of that char!
echo -s then it's converting decimal to binary
echo -s The scheme for converting to decimal to binary is as follows:
echo -s 00000000 now they can either be 0's or 1's and here's what they represent:
echo -s 0=128 0=64 0=32 0=16 0=8 0=4 0=2 0=1 Do you understand that? pretty simple no?
echo -s So that's the same as before... so we know the values
echo -s There's a very easy way to do this that my computer engineering teacher taught me:
echo -s if you have the number 25 and the scheme is 00000000 then all you do is substitute in numbers:
echo -s the 6th 0 is 32... that's over the original number 25!
echo -s the 5th 0 is 16 under it so put a one there... so far we have: 00010000
echo -s the 4th 0 is 8 add it to 16(the 5th 0) if you go over 25 then it's a 0, it doesn't we're at 24!
echo -s the 3rd 0 is 4, if we add that to our value (24) we go over 25... no good make it a 0
echo -s the 2nd 0 is 2, if we add that to out value (24) we go over 25... scrap it.. make it 0
echo -s the 1st 0 is 1, add that to 24 we get 25... therefor our number is: 00011001!
echo -s ------------------------------------------
echo -s END TRANSMISSION!
}
if (\$2 == bin-chr) {
echo -s START TRANSMISSION:
echo -s ------------------------------------------
echo -s Let's get started, Binary is a simple language containing 1's and 0's
echo -s 1 means true and 0 means false
echo -s The scheme for converting to decimal from binary is as follows:
echo -s 00000000 now they can either be 0's or 1's and here's what they represent:
echo -s 0=128 0=64 0=32 0=16 0=8 0=4 0=2 0=1 Do you understand that? pretty simple no?
echo -s Ok so now you know the values of each 0... if it's zero that means it's false
echo -s As I've previously stated... if it's 1 that means that number is true!
echo -s so if you see: 00000001 that equals 1, 00000010 equals 2 00000100 equals 4 and so on!
echo -s now... if you see something like: 00000011 that equals 3 because you add both the values together!
echo -s so there for 00001010 equals? 10! and 11111111 equals? 255!
echo -s If you see binary like this: 110101 that is the same as 00110101
echo -s Or if you see binary like this: 1 that is the same as 00000001!
echo -s so if a binary number starts with a zero.. that/those zero(s) does/do not count!
echo -s this is the same so far.. now we need to ASCII chart to transfer the number to character!
echo -s or you can press ALT + (the number on numpad)!
echo -s ------------------------------------------
echo -s END TRANSMISSION!
}
}
}
``````

DarthReven   -  Mar 29, 2005

or something like that

More
DarthReven   -  Mar 29, 2005

you could handle an entire word useing this: var %x \$strip(\$1) { var %b 1,%y | while (%b >= \$len(%x)) { %y = \$addtok(%x,\$iif(%b == 1,\$+(binaryof,\$left(%x,1),is,\$base(\$left(%x,1),10,2)),\$+(binaryof,\$left(\$mid(%x,%b),1),is,\$base(\$left(\$mid(%x,%b),1))) | inc %b } | msg \$chan Text: \$+(%x,\$chr(44)) \$replacecs(%y,\$chr(95),\$chr(32)) } }

More
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.