Re: Write Hex Bytes

2019-02-21 Thread Keisuke Miyako via 4D_Tech
> 2019/02/22 9:45、Keisuke Miyako via 4D_Tech <4d_tech@lists.4d.com>のメール:
> the task was to process a single value 78,487,500 or 0xCC9FAD04;


correction:

decimal 78,487,500 is 0x04AD9FCC

> If I have a number 78487500, this translates to CC 9F AD 04.


but PC byte ordering will give you CC 9F AD 04 (as Justin correctly pointed out)




**
4D Internet Users Group (4D iNUG)
Archive:  http://lists.4d.com/archives.html
Options: https://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:4d_tech-unsubscr...@lists.4d.com
**

Re: Write Hex Bytes

2019-02-21 Thread Keisuke Miyako via 4D_Tech
you're right,
I re-read the OP,
the task was to process a single value 78,487,500 or 0xCC9FAD04;
not 4 separate decimal values 78, 48, 75 and 00

> 2019/02/22 9:43、Justin Carr via 4D_Tech <4d_tech@lists.4d.com>のメール:
>
> C_BLOB($vX_Data)
> C_LONGINT($vL_Offset)
>
> $vL_Offset:=0
> LONGINT TO BLOB(78487500;$vX_Data;PC byte ordering;$vL_Offset)




**
4D Internet Users Group (4D iNUG)
Archive:  http://lists.4d.com/archives.html
Options: https://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:4d_tech-unsubscr...@lists.4d.com
**

Re: Write Hex Bytes

2019-02-21 Thread Justin Carr via 4D_Tech
On 22 Feb 2019, at 10:30 am, Keisuke Miyako via 4D_Tech <4d_tech@lists.4d.com> 
wrote:
> 
> it sounds like you are over-thinking :)
> 
> you could just do
> 
> SET BLOB SIZE($bytes;4)
> 
> $bytes{0}:=78
> $bytes{1}:=48
> $bytes{2}:=75
> $bytes{3}:=00
> 
> then BLOB TO DOCUMENT.
> 
> not need to go through hex.

Or even easier:

C_BLOB($vX_Data)
C_LONGINT($vL_Offset)

$vL_Offset:=0
LONGINT TO BLOB(78487500;$vX_Data;PC byte ordering;$vL_Offset)

**
4D Internet Users Group (4D iNUG)
Archive:  http://lists.4d.com/archives.html
Options: https://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:4d_tech-unsubscr...@lists.4d.com
**

Re: Write Hex Bytes

2019-02-21 Thread Keisuke Miyako via 4D_Tech
it sounds like you are over-thinking :)

you could just do

SET BLOB SIZE($bytes;4)

$bytes{0}:=78
$bytes{1}:=48
$bytes{2}:=75
$bytes{3}:=00

then BLOB TO DOCUMENT.

not need to go through hex.

2019/02/22 9:27、Peter Mew via 4D_Tech 
<4d_tech@lists.4d.com>のメール:
If I have a number 78487500, this translates to CC 9F AD 04.



**
4D Internet Users Group (4D iNUG)
Archive:  http://lists.4d.com/archives.html
Options: https://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:4d_tech-unsubscr...@lists.4d.com
**

Re: Write Hex Bytes

2019-02-21 Thread Peter Mew via 4D_Tech
Hi
Actually, I dont think this quite what I want, Unless Im Misunderstanding
whats going on.
If I have a number 78487500, this traslates to CC 9F AD 04.
If I carry out your method, I get 8 bytes added to the initial string.
However,If I read the hex number from a file on disc, it only takes up 4
bytes
So CC is 1 byte, 9F is one byte, and so on
This what I want
To be able to add the Hex string to an existing string, so when I look at
it on disc it only takes up 4 bytes
To see this in action, look at the first 12 Bytes of any wav header
Bytes 1-4 hold the Hex version of the Letters RIFF
the next 4 Bytes hold the Hex version of the total length of the file-8
bytes
Bytes 9-12 hold the Hex Version of the Letters WAVE and so on.
What I want is, knowing the Total Length of the File in Hex, How do I
arrange the string I;m going to write to file, so the Length is comtained
in 4 bytes, Including padding bytes if necessary
Sorry, long winded explanation
thanks
-pm

On Thu, Feb 21, 2019 at 11:22 PM Peter Mew  wrote:

> Hi
> Yes, Thats it almost exactly, I just need to convert to little endian, I
> think I can manage that!
> Thanks
> -pm
>
> On Thu, Feb 21, 2019 at 10:45 PM Arnaud de Montard via 4D_Tech <
> 4d_tech@lists.4d.com> wrote:
>
>>
>> > Le 21 févr. 2019 à 22:09, Peter Mew via 4D_Tech <4d_tech@lists.4d.com>
>> a écrit :
>> >
>> > Hi
>> > This is driving me mad, so I hope someone will point me in the right
>> > direction.
>> > I have a string of text.
>> > I can find its length in Hex. now I want to write this length as 4 hex
>> > bytes, into the string, with the aim of doing a text to blob, later on.
>> > If I just add the Hex Number to the string it takes 8 bytes
>> > (String+HexByte0+HexByte1+HexByte2+HexByte3)
>> > If I convert the Hex Numbers to decimal and Do
>> > String+char(DecByte0)+char(DecByte1) etc.
>> > It takes up 4 Bytes but the Numbers written to the string are wrong.
>>
>> Something like that?
>>
>> $hello:="hello world!"
>> $len:=Length($hello)
>> $hex:=String($len;"&x")
>> $hex:=Substring($hex;3)
>> $string:=$hex+$hello+"x"
>> C_BLOB($blb)
>> $charset:="utf-8"
>> CONVERT FROM TEXT($string;$charset;$blb)
>> $string2:=Convert to text($blb;$charset)
>> $offset:=4
>> $hex2:=Substring($string2;1;$offset)
>> $len2:=hexaToDecimal ($hex2)
>> $hello2:=Substring($string2;$offset+1;$len2)
>> ASSERT($len2=$len)
>> ASSERT($hex2=$hex)
>> ASSERT($hello2=$hello)
>>
>> --
>> Arnaud de Montard
>>
>>
>>
>> **
>> 4D Internet Users Group (4D iNUG)
>> Archive:  http://lists.4d.com/archives.html
>> Options: https://lists.4d.com/mailman/options/4d_tech
>> Unsub:  mailto:4d_tech-unsubscr...@lists.4d.com
>> **
>
>
**
4D Internet Users Group (4D iNUG)
Archive:  http://lists.4d.com/archives.html
Options: https://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:4d_tech-unsubscr...@lists.4d.com
**

Re: Write Hex Bytes

2019-02-21 Thread Peter Mew via 4D_Tech
Hi
Yes, Thats it almost exactly, I just need to convert to little endian, I
think I can manage that!
Thanks
-pm

On Thu, Feb 21, 2019 at 10:45 PM Arnaud de Montard via 4D_Tech <
4d_tech@lists.4d.com> wrote:

>
> > Le 21 févr. 2019 à 22:09, Peter Mew via 4D_Tech <4d_tech@lists.4d.com>
> a écrit :
> >
> > Hi
> > This is driving me mad, so I hope someone will point me in the right
> > direction.
> > I have a string of text.
> > I can find its length in Hex. now I want to write this length as 4 hex
> > bytes, into the string, with the aim of doing a text to blob, later on.
> > If I just add the Hex Number to the string it takes 8 bytes
> > (String+HexByte0+HexByte1+HexByte2+HexByte3)
> > If I convert the Hex Numbers to decimal and Do
> > String+char(DecByte0)+char(DecByte1) etc.
> > It takes up 4 Bytes but the Numbers written to the string are wrong.
>
> Something like that?
>
> $hello:="hello world!"
> $len:=Length($hello)
> $hex:=String($len;"&x")
> $hex:=Substring($hex;3)
> $string:=$hex+$hello+"x"
> C_BLOB($blb)
> $charset:="utf-8"
> CONVERT FROM TEXT($string;$charset;$blb)
> $string2:=Convert to text($blb;$charset)
> $offset:=4
> $hex2:=Substring($string2;1;$offset)
> $len2:=hexaToDecimal ($hex2)
> $hello2:=Substring($string2;$offset+1;$len2)
> ASSERT($len2=$len)
> ASSERT($hex2=$hex)
> ASSERT($hello2=$hello)
>
> --
> Arnaud de Montard
>
>
>
> **
> 4D Internet Users Group (4D iNUG)
> Archive:  http://lists.4d.com/archives.html
> Options: https://lists.4d.com/mailman/options/4d_tech
> Unsub:  mailto:4d_tech-unsubscr...@lists.4d.com
> **
**
4D Internet Users Group (4D iNUG)
Archive:  http://lists.4d.com/archives.html
Options: https://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:4d_tech-unsubscr...@lists.4d.com
**

Re: Write Hex Bytes

2019-02-21 Thread Arnaud de Montard via 4D_Tech

> Le 21 févr. 2019 à 22:09, Peter Mew via 4D_Tech <4d_tech@lists.4d.com> a 
> écrit :
> 
> Hi
> This is driving me mad, so I hope someone will point me in the right
> direction.
> I have a string of text.
> I can find its length in Hex. now I want to write this length as 4 hex
> bytes, into the string, with the aim of doing a text to blob, later on.
> If I just add the Hex Number to the string it takes 8 bytes
> (String+HexByte0+HexByte1+HexByte2+HexByte3)
> If I convert the Hex Numbers to decimal and Do
> String+char(DecByte0)+char(DecByte1) etc.
> It takes up 4 Bytes but the Numbers written to the string are wrong.

Something like that? 

$hello:="hello world!"
$len:=Length($hello)
$hex:=String($len;"&x")
$hex:=Substring($hex;3)
$string:=$hex+$hello+"x"
C_BLOB($blb)
$charset:="utf-8"
CONVERT FROM TEXT($string;$charset;$blb)
$string2:=Convert to text($blb;$charset)
$offset:=4
$hex2:=Substring($string2;1;$offset)
$len2:=hexaToDecimal ($hex2)
$hello2:=Substring($string2;$offset+1;$len2)
ASSERT($len2=$len)
ASSERT($hex2=$hex)
ASSERT($hello2=$hello)

-- 
Arnaud de Montard 



**
4D Internet Users Group (4D iNUG)
Archive:  http://lists.4d.com/archives.html
Options: https://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:4d_tech-unsubscr...@lists.4d.com
**

Re: Write Hex Bytes

2019-02-21 Thread Chip Scheide via 4D_Tech
**IF** I understand what you are trying to do
you are halfway there in both cases, and is fairly easy.

I think what you want is:
String+Hex[[1]]+Hex[[2]]+...+Hex[[n]]

Example:
"This is my string of which I want the length"
(decimal) 44 characters
44 (dec) = 2C (hex)

final value:
"This is my string of which I want the length2C

so...
$Text:=
$Hex_Length_txt:=myutl_Convert_to_Hex(LENGTH($Text))
$Text:=$Text+$Hex_Length_txt

code for converting to hex:
PHP Execute("";"dechex";$Hex_Value;$Decimal_Value)
NOTES:
- this has a max decimal conversion value of +/- MAXLONGINT
- the hex value is returned in $Hex_Value
- "dechex" is the PHP library command
- first empty string is library path ("" = main/basic PHP library)


On Thu, 21 Feb 2019 21:09:51 +, Peter Mew via 4D_Tech wrote:
> Hi
> This is driving me mad, so I hope someone will point me in the right
> direction.
> I have a string of text.
> I can find its length in Hex. now I want to write this length as 4 hex
> bytes, into the string, with the aim of doing a text to blob, later on.
> If I just add the Hex Number to the string it takes 8 bytes
> (String+HexByte0+HexByte1+HexByte2+HexByte3)
> If I convert the Hex Numbers to decimal and Do
> String+char(DecByte0)+char(DecByte1) etc.
> It takes up 4 Bytes but the Numbers written to the string are wrong.
> Please help
> thanks
> -pm
> **
> 4D Internet Users Group (4D iNUG)
> Archive:  http://lists.4d.com/archives.html
> Options: https://lists.4d.com/mailman/options/4d_tech
> Unsub:  mailto:4d_tech-unsubscr...@lists.4d.com
> **
---
Gas is for washing parts
Alcohol is for drinkin'
Nitromethane is for racing 
**
4D Internet Users Group (4D iNUG)
Archive:  http://lists.4d.com/archives.html
Options: https://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:4d_tech-unsubscr...@lists.4d.com
**