Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 ASCII to binary
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Thuged_Out_G




PostPosted: 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
Sponsor
sponsor
Tony




PostPosted: Sun Dec 14, 2003 3:49 am   Post subject: (No subject)

well you get the ASCII value using ord()

code:

put ord("a")


then use intstr() fucntion to convert it to binary Laughing
code:

put intstr(ord("a"),0,2)
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Thuged_Out_G




PostPosted: 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




PostPosted: 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.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Dan




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

yes tony come to dark side with me, use the intstr Twisted Evil

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 Evil
Computer Science Canada Help with programming in C, C++, Java, PHP, Ruby, Turing, VB and more!
Thuged_Out_G




PostPosted: 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




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

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




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

hex is base 16 .... base 8 is octal
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: 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.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Andy




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

why use rem when u can use div?
PaddyLong




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




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

i meant to say mod
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 12 Posts ]
Jump to:   


Style:  
Search: