Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Bool
#8
slenkar Wrote:so one byte is 8 bits or 8 'switches'?

so how would you say read or write a 'switch' in a byte? say I wanted to read switch 4 and read switch 5
Yes.
Reading:
Code:
switch4=(byte>>4)&1
Code:
switch5=(byte>>5)&1
Writing:
Code:
poke address,(peek address)|(switch4<<4)
Code:
poke address,(peek address)|(switch5<<5)
Note, I used parenhisis because I noted that bit shifting has lower priority in ZXBC than binary AND opposed to FreeBASIC and other BASIC dialects
Code:
switch4=byte>>4&1
is not working as expected because Boriel is using C priority. See this:
<!-- l --><a class="postlink-local" href="http://www.boriel.com/forum/post2064.html#p2064">post2064.html#p2064</a><!-- l -->
I found the english precedence table of Freebasic which shows that SHL and SHR have higher priority than +/- and binary AND, OR etc.
<!-- m --><a class="postlink" href="http://www.freebasic.net/wiki/wikka.php?wakka=OpPrecedence">http://www.freebasic.net/wiki/wikka.php ... Precedence</a><!-- m -->
------------------------------------------------------------
http://lcd-one.da.ru redirector is dead
Visit my http://members.inode.at/838331/index.html home page!
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)