Thread: binary to ASCII conversion

  1. #1
    Registered User
    Join Date
    Mar 2006
    Posts
    7

    binary to ASCII conversion

    can i write a code to convert a binary number into an ASCII one, has anyone done it? thank you

  2. #2
    Registered Luser cwr's Avatar
    Join Date
    Jul 2005
    Location
    Sydney, Australia
    Posts
    869
    I'm not sure what you're asking. It makes no more sense than converting a chicken into a telephone. ASCII is not a numbering system, it's a set of values that correspond to a set of characters. For example, 65 is the value of 'A' using ASCII. An example of a binary number would be 1000001. This number when converted to decimal is 65.

    Please explain more clearly what you want to achieve. Are you stuck with converting 1000001 to 65, or are you stuck converting 65 to 'A' (for example)?

  3. #3
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Only you know if you can. Yes, someone has. You're welcome.


    Quzah.
    Hope is the first step on the road to disappointment.

  4. #4
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,079
    Sure, it's easy if you know how binary works.

    0000 0000
    This is a single byte in binary (8 bits) Each bit in the byte has a weighted value. Starting from the right bit with 1, and then doubling with each bit to the left.
    Code:
    0   0   0   0     0   0   0   0
    128 64  32  16    8   4   2   1
    If you add that up, that totals 256 possible numbers (0 - 255). Just take your byte in binary, apply the weighted values to the bits that are 1, and then cast your result as a character.

    An example:
    Code:
    0   1   0   1     0   1   1   1
        64      16        4   2   1
    64 + 16 + 4 + 2 + 1 = 87 = 'W'

    You see?
    Last edited by SlyMaelstrom; 03-01-2006 at 09:31 AM.
    Sent from my iPadŽ

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. Binary to Ascii Conversion
    By codemaster12 in forum C Programming
    Replies: 2
    Last Post: 10-24-2007, 10:57 AM
  3. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  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