Subject:
|
Re: what is poke and peek command
|
Newsgroups:
|
lugnet.robotics.handyboard
|
Date:
|
Fri, 7 Aug 1998 16:14:00 GMT
|
Original-From:
|
Will <willbain@cs^AvoidSpam^.umt.edu>
|
Reply-To:
|
WILLBAIN@antispamCS.UMT.EDU
|
Viewed:
|
1440 times
|
| |
| |
phillip chia wrote:
> How to understand what is poke( 1009, 0x20) and bit set (1008, 0x20) ?
> What is 0 x20 and 0x30 ? how to interpret it ? when should I use 0x20
> ,0x30, or 0x40 ?
<snip>
The poke command writes a byte (eight bits) into memory. The peek
command reads a byte from memory. The bit_set command turns on the
specified bits of a byte in memory, but leaves the other bits
unaffected.
An integer constant that begins with 0x is in hexadecimal (base 16)
format, and each digit can range from zero to F. For instance, 0x20 is
equivalent to 32 in decimal (i.e. 2*16 + 0*1). To figure out which bits
would be set by a bit_set( loc, 0x20 ) statement, convert the
hexadecimal to binary. Each hex digit represents four bits, so 0x20 is
the same as 0010 0000 in binary (the first group of four bits is 2 in
binary and the second group is zero).
The difference between poke and bit_set can best be illustrated by an
example. Say the current byte value stored in a particular memory
location is 0xD6 (that's 1110 0110 in binary). Poke( loc, 0x30 ) would
simply replace the current value with the 0x30, but bit_set( loc, 0x30 )
would make the result the logical OR of the current value and the 0x30
mask value:
bit_set( loc, 0x30 );
1110 0110 current value 0xD6
OR 0011 0000 the mask value 0x30
---------------
1111 0110 the result 0xF6 (246 in decimal)
The bit_clear simply clears any bits that are specified in the mask,
leaving the others unaffected (it's the logical AND NOT of the current
value and the mask value):
bit_clear( loc, 0x30 );
1110 0110 current value 0xD6
AND NOT 0011 0000 the mask value 0x30
---------------
...which can be rewritten as:
1110 0110 current value 0xD6
AND 1100 1111 the NOT of the mask value
---------------
1100 0110 the result 0xC6 (198 in decimal)
Hope this helps. Good luck!
--Will
, ,
__@_/ \_@__ |/
| /__, o @_/
)\ ) ( \ (\/\\,
~~~~~~~~~ ' ` ~~~~~~~~~~~ ` ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Wendy Parson, I don't want to achieve immortality through my work.
Will Bain, I want to achieve it through not dying.
& Tatoosh --Woody Allen
|
|
Message is in Reply To:
| | what is poke and peek command
|
| Hi, How to understand what is poke( 1009, 0x20) and bit set (1008, 0x20) ? What is 0 x20 and 0x30 ? how to interpret it ? when should I use 0x20 ,0x30, or 0x40 ? what is all these ? Please advice ? I need to understand it so that I can proceed to (...) (26 years ago, 6-Aug-98, to lugnet.robotics.handyboard)
|
2 Messages in This Thread:
- Entire Thread on One Page:
- Nested:
All | Brief | Compact | Dots
Linear:
All | Brief | Compact
|
|
|
|