Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Two memory locations M1 and M2, contain 32 bit values.

Two memory locations M1 and M2, contain 32 bit values.
Write a program to compare the 3 bit values ( bit19,bit18,bit17)of M1
with 3 bit values ( bit9,bit8,bit7) of M2 and print EQUAL if they are equal


Comments

  • Malcolm_McLeanMalcolm_McLean Posts: 253Member ✭✭
    : Two memory locations M1 and M2, contain 32 bit values.
    : Write a program to compare the 3 bit values ( bit19,bit18,bit17)of M1
    : with 3 bit values ( bit9,bit8,bit7) of M2 and print EQUAL if they
    : are equal
    :
    It's a bit of a bad question, because a program cannot compare two memory locations, unless it has access to core memory it doesn't own.

    I suspect the teacher means "input two 32 it numbers".

    long is guaranteed to be at least 32 bits. So you can use scanf("%ld" ...) to input the numbers.
    Then use the and (&) and shift (>>) operators to manipulate your bits, and printf() to output the result.


  • Ed HallEd Hall Posts: 395Member
    This seems rather simple on a 32 bit machine and compiler:

    Use unsigned int and grab the two values

    Create two masks to isolate the important bits

    Use bitwise and & to modify the two values

    Use bitwise shift << or >> to move one or the other value 10 bits
    (Or, you could simply multiply or divide by the appropriate value)

    Use simple if() to compare the new values

    It should only take about seven actual lines of code.

    Take Care,
    Ed
  • LundinLundin Posts: 3,711Member
    : It's a bit of a bad question, because a program cannot compare two
    : memory locations, unless it has access to core memory it doesn't own.

    Nobody said "Windows"! :-)
Sign In or Register to comment.