Thread: Quick question. Memory and Bitshifting

  1. #1
    Registered User
    Join Date
    Dec 2008
    Location
    Birmingham, UK.
    Posts
    14

    Quick question. Memory and Bitshifting

    Im following a question from a book. Basically I need to convert an unsigned int to decimal and I have to use BitShifting and BitMasking.

    So, I have my 32 bit number stored in an unsigned variable (number 12).

    I need to use a bit mask, and shift right, then use bitwise and to compare them. The output would then be a 32 bit binary representation of the number.

    Im accessing the number 12 directly in memory. Then incrementing by 1 each time and bitshifting by 1. Which way is the binary number stored in memory? Would the first element be the LSB or MSB on a 32 bit Vista machine?

    And how do I store the binary representation? Array of integers? or characters? Seen as C has limited datatypes.

    Thanks for any help.

  2. #2
    Registered User
    Join Date
    Dec 2008
    Location
    Birmingham, UK.
    Posts
    14
    Actually,

    I know. I dont need to loop through memory for the int. If I just create a loop that runs through 32 times, and compare the int to the bitmask, shifting by 1 each time through the loop, that should work. I hope.

Popular pages Recent additions subscribe to a feed