[theforce]
10-11-2004, 08:27 PM
ok i want to write a c++ program where i could type a letter or number and get the binary as output. can someone guide me as to how i should do this? like what would my 1st step be, what would my 2nd step be etc...
|
Click to See Complete Forum and Search --> : C++ program, how to begin. [theforce] 10-11-2004, 08:27 PM ok i want to write a c++ program where i could type a letter or number and get the binary as output. can someone guide me as to how i should do this? like what would my 1st step be, what would my 2nd step be etc... bryan.6 10-11-2004, 08:53 PM do you understand c++ and want us to describe how you achieve this in linux? or would you like us to write a tutorial for you on how to write c++ in general? bwkaz 10-11-2004, 10:26 PM 0th step: Open a text editor. 1st step: Put your text editor into insert mode, if necessary 2nd step: Type in the character '#' 3rd step: Type in the character 'i' 4th step: Type in the character 'n' 5th step: Type in the character 'c' ... Do you seriously expect me to finish that? :p What you are asking for is pretty basic (actually it's perfectly doable in C, you don't need C++). It also sounds very much like a homework assignment... in which case, you might have better luck asking for help from whoever's teaching you. Seeing as it's entirely possible that your professor / teacher / whoever reads these forums as well. ;) [theforce] 10-11-2004, 11:55 PM i am familiar with c++ mostly as im teaching my self c++ through the "Teach yourself c++ in 21 days" so this is not a homeworks assignment, its just for my personal improvement. ive read around 200 pages out of that 600 pages book so i thought id do something outside the book. i could do this in windows using visual c++, but im dual booting linux so i thought id do it in Kdevelop and learn that in the process of writing this program so basically this is a program just for me that i want to write just for kicks and learn Kdevelop. so like i said im familiar with the c++ syntax and keywords and all that (in windows). what i was asking was tips, like how would i start this, like possible i could use all the letters and numbers as part of the program or i could use some functions from c++ that lets me inserts a letter/number and using an alogirthm convert it into binary and then output that as the result. bwkaz 10-12-2004, 06:59 PM The book doesn't cover std::cin or std::cout? As for the algorithm to convert the character to its ASCII value, you don't. Characters are already stored as ASCII values, so all you really have to do is cast it to an int: char ch = 'A'; // this could come from std::cin std::cout << "'A' in hex is: 0x" << std::hex << (int)ch << std::endl; From hex to binary isn't too hard, but there's no standard iostream manipulator to do it for you. [theforce] 10-12-2004, 07:26 PM the book covers basic input, cin, cout, namespaces aswell. its a really nice book. btw thanks for the feedback. ill keep that in mind justlinux.com
Copyright Internet.com Inc. All Rights Reserved. |