boundaries (byte/long) [again?]
I have a table, HouseCode, of 16 Byte values in the DAT area.
A given number, X, from 1-256 is supposed to correlate to one of these table values.
i.e. if X is between 1-16, the first table value is matched; 17-32 gives the 2nd value, etc.
I use H := HouseCode[noparse][[/noparse] (X-1 ) / 16 ] to get the value (H is a local *long* variable).
It's OK for X 1-16; it picks up HouseCode[noparse][[/noparse]0]
But for X 17-32, it gets HouseCode; for X 33-48, it gets HouseCode[noparse][[/noparse]8]
It almost seems like it's jumping by Longs instead of bytes.
Seems like i'm missing some fundamental concept here (?)
-- Don
A given number, X, from 1-256 is supposed to correlate to one of these table values.
i.e. if X is between 1-16, the first table value is matched; 17-32 gives the 2nd value, etc.
I use H := HouseCode[noparse][[/noparse] (X-1 ) / 16 ] to get the value (H is a local *long* variable).
It's OK for X 1-16; it picks up HouseCode[noparse][[/noparse]0]
But for X 17-32, it gets HouseCode; for X 33-48, it gets HouseCode[noparse][[/noparse]8]
It almost seems like it's jumping by Longs instead of bytes.
Seems like i'm missing some fundamental concept here (?)
-- Don
Comments
pri ProcessCmd | B, H, UF
case Param[noparse][[/noparse]0] ' the command
1,3 : ' OFF or ON
if Param => 1 and Param =< 256 'units 1-256 only
H := HouseCode[noparse][[/noparse] (Param-1 ) / 16 ] ' Param is the "X" in my original post. It prints out OK
UF := UnitCode[noparse][[/noparse] ( Param-1 ) // 16 ] ' Interestingly this calculation works OK
B~ ' B=0
B |= (H<<28) ' This gets botched up
B |= (UF<<23) ' this seems to come out oK
if Param[noparse][[/noparse]0]==1 ' no problem with this block
B |= (Off<<18)
else
B |= (On<<18)
text.str(string(" cmd OK B=" ))
text.dec(H) ' diagnostically I'm just looking at H and finding it is wrong if Param is > 16
' text.bin(B,32)
text.out(CR)
else
text.str(string("unit number out of range",13))
DAT
HouseCode
byte %0110 'A
byte %1110 'B
byte %0010 'C
byte %1010 'D
byte %0001 'E
byte %1001 'F
byte %0101 'G
byte %1101 'H
byte %0111 'I
byte %1111 'J
byte %0011 'K
byte %1011 'L
byte %0000 'M
byte %1000 'N
byte %0100 'O
byte %1100 'P
What still is strange is that following after the HouseCode table is one called UnitCode, where I make the same mistake, but it works OK.
-- Don