Hi. Just wanted to know if there was an easier way of getting the upper and lower byte of a 16 bit word
I am using the following functions but still have trouble with Upper byte:
Function HiByte(myTestWord as word) as byte
dim myHiByte as byte
dim TempWord as word
TempWord = 0
if myTestWord > 255 then
TempWord = myTestWord & 0xff00
myHiByte = (TempWord / 256)
End If
HiByte = myHiByte
End Function
Function LoByte(myTestWord as word) as byte
Dim myLoByte as byte
MyLoByte = 0
If myTestWord > 255 then
myLoByte = myTestWord & 0xff
Else
myLoByte = myTestWord
End If
LoByte = myLoByte
End Function
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
There are a few ways to get to the low and high bytes of a variable that are easier than those. If you have:
Dim small As Byte
Dim bigger As Word
You can get the low byte like this:
small = bigger
or the high byte like this:
small = bigger_H
Another option is to create the word variable from a couple of byte variables:
Dim bigger as word alias biggerHigh, biggerLow
Then you can use biggerHigh and biggerLow to read or change the high and low part of the word variable respectively. You can call these byte variables anything you want, they don't need to end in High and Low. It's just the order of the variables after the "alias" that matters.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
When you declare a word variable say "freqCount" GCBasic will use two locations in the register file one called freqCount for the low byte and the other called freqCount_H for the high byte so you can always get the high byte of a word variable by tacking on underscore H to whatever variable name has been used for the word.
dim freqCount as word
freqLo = freqCount ' Low byte assigned to freqLo
freqHi = freqCount_H ' High byte assigned to freqHi
Maybe you could use this instead of the functions?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi. Just wanted to know if there was an easier way of getting the upper and lower byte of a 16 bit word
I am using the following functions but still have trouble with Upper byte:
Function HiByte(myTestWord as word) as byte
dim myHiByte as byte
dim TempWord as word
TempWord = 0
if myTestWord > 255 then
TempWord = myTestWord & 0xff00
myHiByte = (TempWord / 256)
End If
HiByte = myHiByte
End Function
Function LoByte(myTestWord as word) as byte
Dim myLoByte as byte
MyLoByte = 0
If myTestWord > 255 then
myLoByte = myTestWord & 0xff
Else
myLoByte = myTestWord
End If
LoByte = myLoByte
End Function
There are a few ways to get to the low and high bytes of a variable that are easier than those. If you have:
Dim small As Byte
Dim bigger As Word
You can get the low byte like this:
small = bigger
or the high byte like this:
small = bigger_H
Another option is to create the word variable from a couple of byte variables:
Dim bigger as word alias biggerHigh, biggerLow
Then you can use biggerHigh and biggerLow to read or change the high and low part of the word variable respectively. You can call these byte variables anything you want, they don't need to end in High and Low. It's just the order of the variables after the "alias" that matters.
When you declare a word variable say "freqCount" GCBasic will use two locations in the register file one called freqCount for the low byte and the other called freqCount_H for the high byte so you can always get the high byte of a word variable by tacking on underscore H to whatever variable name has been used for the word.
Maybe you could use this instead of the functions?
Thank you Verry much for the quick response. I really enjoy working with gcbasic.