Bin2val

Find quick help here to get you started with Hollywood
Post Reply
DieterG
Posts: 20
Joined: Tue Oct 23, 2018 9:40 pm

Bin2val

Post by DieterG »

Hello,
i need a function to convert variable 1-6 chars from a
raw input string to a value.
The input have first the length of the following value,
it looks in hex e.g.:
.... 04 03 A3 47 21 .....( really there are bytevalues 4,3,$A3,$47 and $21 , not ascii.
So i know the 04 shows the length, and $3A34721 is the value in hex.
I get it easy with midstr.
To convert this in dezimal there is no function in stringfunctions, only for the backward way, i think.

Yes, i wrote a little function to read byte for byte, get ascii-values, multiply the higher with 256 in a for next loop to calculate the result.
This works and all looks good.
But because i must get many values and my function is slow the whole program slow down.
Now my question: is there alteady a function which made this easy ( and quicker) ?
Dieter
User avatar
airsoftsoftwair
Posts: 5433
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: Bin2val

Post by airsoftsoftwair »

I think what you're looking for is the Val() function, isn't it?
DieterG
Posts: 20
Joined: Tue Oct 23, 2018 9:40 pm

Re: Bin2val

Post by DieterG »

I think not, because i get no guildy result if there more then one byte length or there is not an ascii value.
I have already tried with e.g. „$“ before the byte or partstring.
The result shows to be only correct if there a byte and this is not a null-byte.

Code: Select all

len[segment]=val(mid$(trans$,pos[segment]-1,1,#encoding_raw))
Value=val(midstr(trans$,pos[segment],len[segment]-pos[segment],#encoding_raw))
Debugprint(„Value=„,Value)
Try it, it breaks often with second mid$ „there should be a value“ or so.
The len and value variable contains silly values.
Also if the len correct, is it not 1 the value is incorrect.
Because the len is allways 1-6 i use asc for the converting and this works fine. But not for the value itself.
I do not know how i should it explain better.
Dieter
User avatar
airsoftsoftwair
Posts: 5433
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: Bin2val

Post by airsoftsoftwair »

Hmm, I'm not really sure what you mean. Can you post some code that I can actually run and try here? Maybe I'll understand it then :)
User avatar
airsoftsoftwair
Posts: 5433
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: Bin2val

Post by airsoftsoftwair »

Oops, upon reading your post again I understand what the problem is. You're dealing with a string containing raw binary data. That of course won't work with Val(). I think we need something new like ByteVal() or so... but there is going to be a limit of 4 bytes then because that is the size of a longword.
User avatar
airsoftsoftwair
Posts: 5433
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: Bin2val

Post by airsoftsoftwair »

Code: Select all

- New: Added ByteStrStr() command; this allows you to convert a value to raw binary data; the value
  can be either an 8-bit (#BYTE), 16-bit (#SHORT), 32-bit (#INTEGER) value, or a 32/64-bit floating
  point value (#FLOAT and #DOUBLE); optionally, you can also specify if the byte order should be big
  endian or little endian
- New: Added ByteVal() command; this allows you to read raw bytes from a string and return them as
  either an 8-bit (#BYTE), 16-bit (#SHORT), 32-bit (#INTEGER) value, or 32/64-bit floating point
  value (#FLOAT and #DOUBLE); optionally, you can also specify if the byte order is big endian or
  little endian
DieterG
Posts: 20
Joined: Tue Oct 23, 2018 9:40 pm

Re: Bin2val

Post by DieterG »

Thx.
Must i wait until Hollywood 7.2 released or where i can get it ?
Dieter
User avatar
airsoftsoftwair
Posts: 5433
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: Bin2val

Post by airsoftsoftwair »

You have to wait for the next version :)
Post Reply