LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-13-2007, 08:24 PM   #1
RevenantSeraph
Member
 
Registered: Jan 2007
Distribution: Ubuntu
Posts: 66

Rep: Reputation: 15
In search of binary translator source code


I am a newbie getting my first real taste of c++ and am trying to incorporate into my project some code that will take the user's input and translate it into binary. I know there are lots of binary translators on the web, and I'd like to use that sort of functionality within my cpp file, but have not yet found any code that helps...
Anyone?

Lots of love,
Reven
 
Old 04-13-2007, 08:37 PM   #2
nadroj
Senior Member
 
Registered: Jan 2005
Location: Canada
Distribution: ubuntu
Posts: 2,539

Rep: Reputation: 60
what do you mean translate it to binary? are you reading input and saving it to a binary file? or just displaying the input converted to binary 1's and 0's?
 
Old 04-13-2007, 09:31 PM   #3
RevenantSeraph
Member
 
Registered: Jan 2007
Distribution: Ubuntu
Posts: 66

Original Poster
Rep: Reputation: 15
Just displaying the 0's and 1's of the translated input, just like any other string. They'll be asked to type their name, so the resulting output shouldn't be too long. It's really just a novelty to fulfill the extra credit portion.

Last edited by RevenantSeraph; 04-13-2007 at 09:34 PM.
 
Old 04-13-2007, 10:03 PM   #4
nadroj
Senior Member
 
Registered: Jan 2005
Location: Canada
Distribution: ubuntu
Posts: 2,539

Rep: Reputation: 60
Code:
read in input and store in a string
for every character in string
    get integer value of the character (ie 'A' = 75 or whatever it is)
    myBinaryStr = intToBin(integer value of character)
    either store this value to another string (and print all at once at end) or print each value right away
end for
of course this magical 'string intToBin(int)' function doesnt exist, thats what you have to make.

edit: of course there are easier ways to do this, that are practically already written for you. but i assume you need to write one yourself.

Last edited by nadroj; 04-13-2007 at 10:10 PM.
 
Old 04-14-2007, 05:38 AM   #5
dmail
Member
 
Registered: Oct 2005
Posts: 970

Rep: Reputation: Disabled
I have a class which does this and Hurb Sutter gives an example of the class which is similar to mine in "Exceptional C++ Style 40 New Engineering Puzzles, Programming problems and solutions"; but its overkill for something like this where the size of the input data type is constant(8 bits).

Basically what you need to be looking at is bit shifting the input and taking the value of the shift.

Here is a couple of links for you
http://www.devx.com/getHelpOn/10Minu...18019/0/page/1
http://www.cprogramming.com/tutorial...operators.html
http://www.informit.com/guides/conte...eqNum=163&rl=1

[edit]I should point out this is not the only way, yet it is the most efficient. If you have a go and can not get it to working post back with your code and I will give a point in the right direction.

Last edited by dmail; 04-14-2007 at 05:44 AM.
 
Old 04-14-2007, 03:49 PM   #6
RevenantSeraph
Member
 
Registered: Jan 2007
Distribution: Ubuntu
Posts: 66

Original Poster
Rep: Reputation: 15
Thanks! I'll get started with that, and will later post the results. It'll take a little time since I'm at work today, but will be back. <3
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: SourceForge.net(R) and Krugle Bring Code Search to World's Largest Open Source Software Repository LXer Syndicated Linux News 0 04-10-2007 04:31 AM
LXer: Krugle offers code search engine for open source, with open source LXer Syndicated Linux News 0 02-27-2007 08:04 AM
source code vrs binary titanium_geek Linux - General 4 12-26-2004 11:01 AM
Looking for source code of Web search engine. George2 Programming 3 05-17-2004 09:56 PM
I want Linux source code for FAT file system in user readable form not in binary form ramya272 Linux - Newbie 5 02-05-2004 07:54 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:57 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration