|
Binary Talk Back
|
|
08-16-2009, 08:11 AM
Post: #1
|
|||
|
|||
|
Binary Talk Back
I saw a topic header here and it gave me an idea. Why not write a program that receives user input and then displays what was received in binary.
example of user input: "text message" would translate to: 111010001100101011110000111010000100000110110101100101011100110111001101100001011001110110010100001010 |
|||
|
08-16-2009, 08:40 AM
Post: #2
|
|||
|
|||
|
RE: Binary Talk Back
Ah so an ASCII to binary converter?
I'll try to this one "Character is determined more by the lack of certain experiences than by those one has had." Friedrich Nietzsche |
|||
|
08-16-2009, 09:00 AM
Post: #3
|
|||
|
|||
|
RE: Binary Talk Back
asci tablature to file, then import when it needs?
But I am lazy to write program
Read rules ![]()
|
|||
|
08-16-2009, 09:58 PM
Post: #4
|
|||
|
|||
|
RE: Binary Talk Back
I was thinking of making ASCII to Binary and Binary to ASCII. Basically you need to make functions Bin to Dec and Dec to Bin !
I already have Decimal to Binary : Code: program dectobin;So i made it faster and with some checking functions inside. It writes binary as a string, but you have to enter decimal and class, or length of binary file in bits (8 for ASCII). After that i was thinking to make bintodec() function. So i think i have the right algorithm. It basically powers 2 and adds on variable. Also there is an inside function that deletes zeros in front (it is recursive). So here is the code wit whole program : Code: program bintodec_program;Code: program ascii_to_bin_and_reversa;"I dont know with what weapons World War 3 will be fought with, but i know World War 4 will be fought with stones and sticks" - Albert Einstein |
|||
|
08-17-2009, 12:49 AM
Post: #5
|
|||
|
|||
|
RE: Binary Talk Back
This is my solution:
Code: #include <stdio.h> |
|||
|
08-17-2009, 04:38 AM
Post: #6
|
|||
|
|||
|
RE: Binary Talk Back
Great G4143, as you can see, solution is much longer in Pascal, because i made everything from scratch, and for both dec to bin and bin to dec,
but i think i understand this, except one line "#define ONE 0x80", and everything about that ONE, can you explain ? "I dont know with what weapons World War 3 will be fought with, but i know World War 4 will be fought with stones and sticks" - Albert Einstein |
|||
|
08-17-2009, 05:19 AM
Post: #7
|
|||
|
|||
RE: Binary Talk Back
(08-17-2009 04:38 AM)drdebcol Wrote: Great G4143, as you can see, solution is much longer in Pascal, because i made everything from scratch, and for both dec to bin and bin to dec, I use 0x80(#define ONE 0x80) to mask out the first bit of the byte. If you look at the binary value of 0x80 it works out to be: 10000000 so any byte that is "and" with 0x80 will return zero if the first bit is zero and not zero if the first bit is one...G143 |
|||
|
08-17-2009, 05:22 AM
Post: #8
|
|||
|
|||
RE: Binary Talk Back
(08-17-2009 05:19 AM)G4143 Wrote:OK now i understand, but Pascal is different, i think you can not define those values !(08-17-2009 04:38 AM)drdebcol Wrote: Great G4143, as you can see, solution is much longer in Pascal, because i made everything from scratch, and for both dec to bin and bin to dec, "I dont know with what weapons World War 3 will be fought with, but i know World War 4 will be fought with stones and sticks" - Albert Einstein |
|||
|
08-17-2009, 06:59 AM
(This post was last modified: 08-17-2009 07:01 AM by G4143.)
Post: #9
|
|||
|
|||
RE: Binary Talk Back
(08-17-2009 05:22 AM)drdebcol Wrote:(08-17-2009 05:19 AM)G4143 Wrote:OK now i understand, but Pascal is different, i think you can not define those values !(08-17-2009 04:38 AM)drdebcol Wrote: Great G4143, as you can see, solution is much longer in Pascal, because i made everything from scratch, and for both dec to bin and bin to dec, In C the "#define ONE 0x80" statement is a macro that gets processed with the pre-processor...essentially the pre-processor scans the source code for any instance of ONE and replaces the it with 0x80 so that the compiler never sees ONE only 0x80 hex...G4143 |
|||
|
08-17-2009, 08:38 PM
(This post was last modified: 08-17-2009 08:38 PM by l3g1sl4tor.)
Post: #10
|
|||
|
|||
|
RE: Binary Talk Back
My weak knowledge in C is ending here
Read rules ![]()
|
|||
|
« Next Oldest | Next Newest »
|









But I am lazy to write program