Thread: binary number in array? urgently help

  1. #1
    Registered User
    Join Date
    Feb 2006
    Posts
    4

    binary number in array? urgently help

    I going to do a project. The output ADC is in binary like 00000001, so may i direct assign these binary value into a particular array? If yes, how i can take out the array content because i need to change the binary to decimal.
    thank you..

  2. #2
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    No, you can't use a binary number directly in your C source file. You can, however, represent an octal or hex number directly in your program:
    Code:
    printf("\222");  /* print octal 222*/
    putchar(0xAb);  /* print hex number AB */
    You can convert a binary number to an octal/hexadecimal number in your head, using a program of your own, or the Windows calculator (switch to Scientific mode).
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  3. #3
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    The binary number 00000001 is pretty easy to represent in decimal, octal, or hexadecimal. 1, \001, or 0x1.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  4. #4
    Registered User
    Join Date
    Feb 2006
    Posts
    4
    ok...binary can not store in array..10s
    let say the value array is hexadecimal because my system will direct and store the hexadecimal in array. i need to convert the hexadecimal to decimal. how can i get out the hexadecimal from the array? is it possible to get it out and then do conversion?

  5. #5
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    printf("%x")? sprintf()?
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Nim Trainer
    By guesst in forum Game Programming
    Replies: 3
    Last Post: 05-04-2008, 04:11 PM
  2. Stone Age Rumble
    By KONI in forum Contests Board
    Replies: 30
    Last Post: 04-02-2007, 09:53 PM
  3. Bitwise OR
    By tinkerbell20 in forum C++ Programming
    Replies: 4
    Last Post: 06-11-2005, 02:23 AM
  4. Struct *** initialization
    By Saravanan in forum C Programming
    Replies: 20
    Last Post: 10-09-2003, 12:04 PM
  5. Array, Linked List, or Binary Tree?
    By Unregistered in forum C Programming
    Replies: 6
    Last Post: 01-05-2002, 10:07 PM