Author 
Message 
Thuged_Out_G

Posted: Sun Dec 14, 2003 3:28 am Post subject: 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 





Sponsor Sponsor



Tony





Thuged_Out_G

Posted: Sun Dec 14, 2003 3:51 am Post subject: (No subject) 


code:  put intstr(ord("a"),0,2) 
what does the ,0,2) mean? [/code] 





Tony

Posted: Sun Dec 14, 2003 4:06 am Post subject: (No subject) 


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. 
Tony's programming blog. DWITE  a programming contest. 




Dan

Posted: Tue Dec 16, 2003 12:37 pm Post subject: (No subject) 


yes tony come to dark side with me, use the intstr
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 
Computer Science Canada
Help with programming in C, C++, Java, PHP, Ruby, Turing, VB and more! 




Thuged_Out_G

Posted: Tue Dec 16, 2003 4:03 pm Post subject: (No subject) 


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

Posted: Tue Dec 16, 2003 5:02 pm Post subject: (No subject) 


so that's the simple of converting to binary... . ..
i was using the div 2 and rem 2 dealy.. the same way as by hand.. now it's so simple.. 





PaddyLong

Posted: Tue Dec 16, 2003 5:35 pm Post subject: (No subject) 


hex is base 16 .... base 8 is octal 





Sponsor Sponsor



Tony

Posted: Tue Dec 16, 2003 6:11 pm Post subject: (No subject) 


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. 
Tony's programming blog. DWITE  a programming contest. 




Andy

Posted: Tue Dec 16, 2003 8:01 pm Post subject: (No subject) 


why use rem when u can use div? 





PaddyLong

Posted: Tue Dec 16, 2003 8:42 pm Post subject: (No subject) 


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...
2516 = 9
9  8 = 1
1  1 = 0
so this means you have the 1, 8 and 16 bits set...
11001 





Andy

Posted: Tue Dec 16, 2003 8:44 pm Post subject: (No subject) 


i meant to say mod 





