Thread: binary to ascii

  1. #1
    Musicman - Canora
    Join Date
    Aug 2005
    Location
    Melbourne
    Posts
    252

    binary to ascii

    Hey guys what would be the easiest way of converting binary to ascii?

  2. #2
    Musicman - Canora
    Join Date
    Aug 2005
    Location
    Melbourne
    Posts
    252
    Sorry could someone explain bit more about bit shifting as i dont fully understanf this

  3. #3
    Math wizard
    Join Date
    Dec 2006
    Location
    USA
    Posts
    582
    Let's take the binary number 11001101 (that's 203 in decimal). If you bitshift left one (that is, have Number << 1), the bits become 10011010. Here's a pictorical view with alignments:

    Code:
    00|11001101|00 // original
    01|10011010|00 // number << 1
    11|00110100|00 // number << 2
    00|01100110|10 // number >> 1
    00|00110011|01 // number >> 2
    The area between the | and | indicates what is being used. Those outside it are discarded (or converted to zeros). That's the general idea. This demonstrates 8-bit, but it works the same no matter how many bits you use, even 1,048,576 (provided there was a data type that big).

    I'm pretty sure that there are some special indications for C (such as getting printf to print the binary representation of the decimal number 168). I, unfortunately, don't know it. There's one for octal and hexadecimal as well.
    High elevation is the best elevation. The higher, the better the view!
    My computer: XP Pro SP3, 3.4 GHz i7-2600K CPU (OC'd to 4 GHz), 4 GB DDR3 RAM, X-Fi Platinum sound, GeForce 460, 1920x1440 resolution, 1250 GB HDD space, Visual C++ 2008 Express

  4. #4
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    What don't you understand about it? It's pretty straight forward... << shifts numbers left, >> shifts numbers right.

    But that has nothing to do with binary to ASCII conversion. There's no conversion that needs to take place at all. The ASCII table is just an ordered group of number values. You can represent a given character in a number of ways, including binary.

    Maybe this will help: http://www.catb.org/~esr/faqs/smart-questions.html
    If you understand what you're doing, you're not learning anything.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Lame null append cause buffer to crash
    By cmoo in forum C Programming
    Replies: 8
    Last Post: 12-29-2008, 03:27 AM
  2. help with c program: binary to ascii program
    By bigmac(rexdale) in forum C Programming
    Replies: 26
    Last Post: 02-03-2008, 02:26 PM
  3. Wininet Binary and ASCII
    By maxorator in forum Windows Programming
    Replies: 5
    Last Post: 11-26-2005, 03:16 AM
  4. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  5. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM