[phpBB Debug] PHP Warning: in file [ROOT]/phpbb/db/driver/mysqli.php on line 264: mysqli_fetch_assoc(): Couldn't fetch mysqli_result
[phpBB Debug] PHP Warning: in file [ROOT]/phpbb/db/driver/mysqli.php on line 326: mysqli_free_result(): Couldn't fetch mysqli_result
Pete's QBASIC Site Discuss QBasic, Freebasic, QB64 and more 2019-10-17T23:16:21-05:00 http://petesqbsite.com/phpBB3/app.php/feed/topic/14539 2019-10-17T23:16:21-05:00 2019-10-17T23:16:21-05:00 http://petesqbsite.com/phpBB3/viewtopic.php?p=38584#p38584 <![CDATA[Re: Finding little-endian values of 24-bit numbers]]>
For example,

Converting &H0000FE to &HFE0000 programmatically with simple commands, not multiple for-next loops going through each ascii character.

Perhaps I should learn more 8086 assembly and use call absolute more.

Statistics: Posted by mikefromca — Thu Oct 17, 2019 11:16 pm


]]>
2019-10-16T12:38:42-05:00 2019-10-16T12:38:42-05:00 http://petesqbsite.com/phpBB3/viewtopic.php?p=38579#p38579 <![CDATA[Re: Finding little-endian values of 24-bit numbers]]> http://www.qb64.net/wiki/index-php/Math ... _and_Bytes

Statistics: Posted by burger2227 — Wed Oct 16, 2019 12:38 pm


]]>
2019-10-16T11:51:28-05:00 2019-10-16T11:51:28-05:00 http://petesqbsite.com/phpBB3/viewtopic.php?p=38578#p38578 <![CDATA[Finding little-endian values of 24-bit numbers]]>
I coded my own hardware so that any numeric parameters needs to be in little-endian format. But I'm finding the PC likes to deal with numbers in big endian format.

Nice thing with Qbasic (which seems to be the only programming language I know that supports this directly) is that I can use mki$ and cvi and friends to help me in my quest.

So as an example, say the required packet format my hardware expects is as follows:

Byte 1: Function number
Bytes 2-4: 24-bit data
Byte 5: checksum

So my qbasic program will convert the string-hex format of the data to ascii to send down the serial line. By string-hex I mean where it prints hex characters as string.

For example, If I wanted to use function number 10 and the 24-bit data is the 24 bit number 254, and the checksum is 20, then in my program, I would have it process the string:

"0AEF000014"

Because 0A is hex for 10, EF0000 is little-endian 24-bit value for 254 and 14 is hex for 20.

Eventually I want to make these values not fixed. Say I want the user to input the 24-bit value in and he types 254 as the number

Somehow I want it to go down the serial line as data equivalent to qbasic's chr$(&HFE)+chr$(0)+chr$(0)

I'll write code to illustrate my point:

Code:

funcn%=10checksum%=14myvalue&=254'convert to output for serialtoser$=chr$(funcn%)+chr$(myvalue& AND 255)+chr$((myvalue&/256) AND &H100)+chr$((myvalue&/&H10000) AND 255)+chr$(checksum%);convert to user readable outputbytes$=""for n%=1 to len(toser$)bytes$=bytes$+right$("00"+hex$(asc(mid$(toser$,n%,1))),2)next n%print bytes$
The above code would achieve what I want but in reality the data packet size is much larger and may involve more numbers.

If my number was a 32-bit number, I could maybe replace my thought of:

Code:

... chr$(myvalue& AND 255)+chr$((myvalue&/256) AND &H100)+chr$((myvalue&/&H10000) AND 255)+chr$(chr$((myvalue&/&H1000000))
with this:

Code:

mkl$(myvalue&)
But what would be best for a 24-bit number? I'm just trying to cut down on the use of chr$() and number divisions.

Statistics: Posted by mikefromca — Wed Oct 16, 2019 11:51 am


]]>