Jump to content

How to find the value in memory address ?

- - - - -

  • Please log in to reply
1 reply to this topic

#1
SLiM_BoY

SLiM_BoY

    Newbie

  • Members
  • Pip
  • 1 posts
Problem : In 8 bit memory assign 5 to 15th address.

Solution :
int main () { 

*(char *)(15) = 5; 

} 

--

Problem : In a 8 bit memory, print True if the value in 3rd address 4th bit is 1, else if the value is 0 print False.

In the 3rd address, we have a binary value. E.g : 11010011. But we don't know that value.

8 Bit Memory
-----------
|.............| 0
|.............| 1
|.............| 2
|11010011| 3
|.............| 4
|.............| 5
|.............| 6
|.............| 7
-----------

I've to get the value in 3rd address and check 4rd bit if it is 1 or 0. And print true - false.

I don't have enough information about pointers to solve that problem. Thanks for replies.

Edited by SLiM_BoY, 01 October 2011 - 02:00 PM.


#2
Flying Dutchman

Flying Dutchman

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 889 posts
  • Location:::1
You can use operator & to check whether 4th is on or off.
char n = 0xAB;


for (int i = 0; i < sizeof(n) * 8; ++i)
    std::cout << "bit" << i << " : " << ((n & (1 << i)) ? "1" : "0") << "\n";

A conclusion is where you got tired of thinking.
#define class struct    // All is public.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users