Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
defining 1 byte variables
#1
I believe the Qbasic integer (num%) is a 2 byte value. How can I define a variable and be sure it is no larger than one byte.
Reply
#2
Code:
dim byte as string * 1
esus saves.... Passes to Moses, shoots, he scores!
Reply
#3
QBASIC is really quite evil for not giving an intrinsic one-byte datatype (instead we have to masquerade it as a string-var).
However, this is what I use when I want access to single bytes.
You're right to say that the INTEGER data type is two bytes.
So, we access single bytes by directly accessing memory.
Code:
DIM Byte AS INTEGER
'Just make sure that Byte never exceeds 255.
'To put a value into the byte:
Value% = 10   'Make sure that never exceeds 255
DEF SEG=VARSEG(Byte)
POKE VARPTR(Byte),Value%
'To retrieve the byte:
WhatIsInTheByte% = PEEK(VARPTR(Byte))
I recomment functions for this - GetByte and StoreByte.
f only life let you press CTRL-Z.
--------------------------------------
Freebasic is like QB, except it doesn't suck.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)