
-----------------------------------
Thuged_Out_G
Sun Dec 14, 2003 3:28 am

ASCII to binary
-----------------------------------
how do you figure out the binary value of an ASCII char/word?
i want to make a program to do this, but i cant do that until i know how to convert ASCII to binary

-----------------------------------
Tony
Sun Dec 14, 2003 3:49 am


-----------------------------------
well you get the ASCII value using ord()


put ord("a")


then use intstr() fucntion to convert it to binary :lol:

put intstr(ord("a"),0,2)


-----------------------------------
Thuged_Out_G
Sun Dec 14, 2003 3:51 am


-----------------------------------
put intstr(ord("a"),0,2) 

what does the ,0,2) mean? [/code]

-----------------------------------
Tony
Sun Dec 14, 2003 4:06 am


-----------------------------------
0 is the length out returning value... works the same as :# after a string, so 0 will not affect the output in any way.

2 is the base to which the number is converted to. 8 will make output a hex.

-----------------------------------
Dan
Tue Dec 16, 2003 12:37 pm


-----------------------------------
yes tony come to dark side with me, use the intstr  :twisted: 

just to let you know that if that is for school your teacher may not like intstr it kind of takes the calangen out of making a to any bases convertor  :twisted:

-----------------------------------
Thuged_Out_G
Tue Dec 16, 2003 4:03 pm


-----------------------------------
no its not for school, i was just interested in how it was done after i downloaded tony's one in VB, i think it was tony who did it

-----------------------------------
santabruzer
Tue Dec 16, 2003 5:02 pm


-----------------------------------
so that's the simple of converting to binary... . :oops: ..
i was using the div 2 and rem 2 dealy.. the same way as by hand.. now it's so simple..

-----------------------------------
PaddyLong
Tue Dec 16, 2003 5:35 pm


-----------------------------------
hex is base 16 .... base 8 is octal

-----------------------------------
Tony
Tue Dec 16, 2003 6:11 pm


-----------------------------------
for my VB one, you basically grab the ord() value of the letter and turn that number into binary.

start from 2^8 and move down. If the number is larger then or equals to 2^counter then bit is 1, subtract value from number, else bit is 0. And so on until 2^0.

-----------------------------------
Andy
Tue Dec 16, 2003 8:01 pm


-----------------------------------
why use rem when u can use div?

-----------------------------------
PaddyLong
Tue Dec 16, 2003 8:42 pm


-----------------------------------
you use the remainder because any number divided by 2 will give a remainder of 0 or 1 ... so to convert from base 10 (decimal) to base 2 (binary) you just keep dividing by two and keeping track of the remainder...
ex..
25 / 2 = 12 R 1
12 / 2 = 6 R 0
6 / 2 = 3 R 0
3 / 2 = 1 R 1
1 / 2 = 0 R 1

then you read from the bottom up and record the remainders...
so 25 base 10 = 11001 base 2

another way is to use the greatest power of 2 that's less than the number...
25-16 = 9
9 - 8 = 1
1 - 1 = 0
so this means you have the 1, 8 and 16 bits set...
11001

-----------------------------------
Andy
Tue Dec 16, 2003 8:44 pm


-----------------------------------
i meant to say mod
