Thread: Binary representation of a number, binary operators.

  1. #1
    Registered User
    Join Date
    May 2005
    Posts
    76

    Binary representation of a number, binary operators.

    Hi,
    I have to deal with a binary representation of a number, starting with most significant bit. The problem is that I don't have enough memory to keep the whole binary representation so I can't just simply convert the number in base 10 to it's binary representation. Is it possible to get every bit from some number starting from MSB (using binary operators) so I don't have to keep whole number's binary representation in memory ?
    Regards.

  2. #2
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Ireland
    Posts
    8,446
    You mean you don't have enough memory to keep an array of 16, 32 or 64 booleans? (C99)

    Anyways, one way you can do this, assuming the value can be antything from a char to a double, is to build a for loop of as many as steps as your number size in bits.

    Then you shift left with the operator <<, taking the MSB. You calculate the mask from your position in the for loop.
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  3. #3
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  4. #4
    Registered User
    Join Date
    May 2005
    Posts
    76
    Thank you for help.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 5
    Last Post: 01-28-2009, 04:34 PM
  2. xor linked list
    By adramalech in forum C Programming
    Replies: 23
    Last Post: 10-14-2008, 10:13 AM
  3. Need help with this compiler error
    By Evangeline in forum C Programming
    Replies: 7
    Last Post: 04-05-2008, 09:27 AM
  4. Binary representation in C
    By @nthony in forum C Programming
    Replies: 25
    Last Post: 11-10-2007, 12:43 AM
  5. Array of boolean
    By DMaxJ in forum C++ Programming
    Replies: 11
    Last Post: 10-25-2001, 11:45 PM