[Gambas-user] Reading hex from a string socket read

Rob sourceforge-raindog2 at ...94...
Thu Feb 19 15:31:35 CET 2004


On Thursday 19 February 2004 09:01, adam krell wrote:
> TwoByteCode = Val(Str$(Asc(Mid$(Buffer,1,1))) &
> Str$(Asc(Mid$(Buffer,2,1))))
> Is there a more efficient way to do this?  

I'd think the following would work to build an int value from two 
bytes of binary data, high byte first:

TwoByteCode = asc(mid$(buffer,1,1)) * 256 + asc(mid$(buffer,2,1))

But that's so different from what you're doing that I need to see 
an example of the input values you're looking at, and the 
expected value of TwoByteCode when you're done.

I know eventually there'll need to be some kind of "pack/unpack" 
function set for Gambas because you need to go from binary to 
hex to integer (or array) a lot when dealing with legacy systems 
and ISO protocols.  I don't think my C's up to that right now, 
though (maybe I can figure out how it works in perl and copy 
their code somehow.... ugh)

Rob





More information about the User mailing list