Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2013-09

represent data string in hex?

12 messages · 4 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Unknown author

i have a static array of strings that i need to fill as hex bytes... i can do this in decimal but it would be easier to convert other data if i can do it in hex since the data is represented in hex...

a[n] := #255;  // works
a[n] := $ff;     // does not work

ideally, there would be multiple bytes...

a[n] := $C2AD  or  a[n] := $C2$AD

help?

Bart
to Unknown author
Show quoted text 8 lines
a[n] := #255; // works a[n] := $ff; // does not work ideally, there would be multiple bytes... a[n] := $C2AD or a[n] := $C2$AD

Not sure what you want:

a[n] := #$FF;  (which equals a[n] := #255)
a[n] := '$FF' (note the single quotes), assuming a[n] is of type String.

Bart

Unknown author
Bart wrote 15 lines
On 9/20/13, wrote: > > a[n] := #255; // works > a[n] := $ff; // does not work > > ideally, there would be multiple bytes... > > a[n] := $C2AD or a[n] := $C2$AD > Not sure what you want: a[n] := #$FF; (which equals a[n] := #255) a[n] := '$FF' (note the single quotes), assuming a[n] is of type String.

yeah, the singles are bad examples... i'm really wanting the multiple byte format to work... i tried both and was told "expected string but found byte" or "word"... it is for a translation table... in quoted-printable, everything is equalsXX... the same codes are used in utf-8... so i thought if i could just copy them directly into my array and then change the equals to dollar...

i ended up getting it to work by wrapping each piece with chr() but that's really ugly visually when looking at the code to see the side by side character and replacement tables...

a[n] := chr($C2)+chr($AD) for two byte codes...

the end result is to translate as much as possible to CP437 for posting in 7bit medium and distribution for others to read... numerous of those reading are sight impaired and do not use any GUI at all... plain DOS 6 for many of them as newer stuff just doesn't work well for them... utf-8 and quoted-printable are just pure fecal material in those environments... so i'm having to do this conversion stuff... in the above two byte example, it is a "soft hyphen" which will be replaced with the good old-fashioned '-' (dash/minus/hyphen) character... there's hundreds of items like this that have a plain 7-bit translation but i haven't found anything that does it as needed... the trade mark, copyright, and service mark symbols are three others... '(tm)', '(c)', and '(sm)' work just fine ;)

i hope that is clearer...

patspiper
to Unknown author
Show quoted text 20 lines
On Friday, September 20, 2013 12:47 PM, Bart wrote: > On 9/20/13, wrote: > >> a[n] := #255; // works >> a[n] := $ff; // does not work >> >> ideally, there would be multiple bytes... >> >> a[n] := $C2AD or a[n] := $C2$AD >> > > Not sure what you want: > > a[n] := #$FF; (which equals a[n] := #255) > a[n] := '$FF' (note the single quotes), assuming a[n] is of type String. yeah, the singles are bad examples... i'm really wanting the multiple byte format to work... i tried both and was told "expected string but found byte" or "word"... it is for a translation table... in quoted-printable, everything is equalsXX... the same codes are used in utf-8... so i thought if i could just copy them directly into my array and then change the equals to dollar... i ended up getting it to work by wrapping each piece with chr() but that's really ugly visually when looking at the code to see the side by side character and replacement tables... a[n] := chr($C2)+chr($AD) for two byte codes...
What about a[n] := #$C2#$AD?

Stephano

Unknown author
patspiper wrote
On 21/09/13 12:15, wrote:

[trim]

Show quoted text 12 lines
> yeah, the singles are bad examples... i'm really wanting the multiple byte > format to work... i tried both and was told "expected string but found byte" or > "word"... it is for a translation table... in quoted-printable, everything is > equalsXX... the same codes are used in utf-8... so i thought if i could just > copy them directly into my array and then change the equals to dollar... > > i ended up getting it to work by wrapping each piece with chr() but that's > really ugly visually when looking at the code to see the side by side character > and replacement tables... > > a[n] := chr($C2)+chr($AD) for two byte codes... What about a[n] := #$C2#$AD?

i haven't tried that... my understanding is that #xx depicts the decimal format of the character...

eg : $FF == #255

but the data i'm working with is in hex format and trying to convert to use the actual characters or converting the hex to decimal is grue... especially when trying to create and maintain the static data tables i'm attempting to build...

anyway, i'll try to find something with regard to using #$C2... hopefully i won't have to spend much time locating anything ;)

patspiper
to Unknown author
Show quoted text 18 lines
On Saturday, September 21, 2013 6:27 AM, patspiper wrote: > On 21/09/13 12:15, wrote: [trim] >> yeah, the singles are bad examples... i'm really wanting the multiple byte >> format to work... i tried both and was told "expected string but found byte" or >> "word"... it is for a translation table... in quoted-printable, everything is >> equalsXX... the same codes are used in utf-8... so i thought if i could just >> copy them directly into my array and then change the equals to dollar... >> >> i ended up getting it to work by wrapping each piece with chr() but that's >> really ugly visually when looking at the code to see the side by side character >> and replacement tables... >> >> a[n] := chr($C2)+chr($AD) for two byte codes... > What about a[n] := #$C2#$AD? i haven't tried that... my understanding is that #xx depicts the decimal format of the character... eg : $FF == #255

It is rather #$FF which is the same as #255, like Chr(255)

Stephano

Unknown author
patspiper wrote
On 21/09/13 18:56, wrote: > On Saturday, September 21, 2013 6:27 AM, patspiper wrote: >> On 21/09/13 12:15, wrote:

...

Show quoted text 7 lines
>>> a[n] := chr($C2)+chr($AD) for two byte codes... >> What about a[n] := #$C2#$AD? > i haven't tried that... my understanding is that #xx depicts the decimal format of the character... > > eg : $FF == #255 It is rather #$FF which is the same as #255, like Chr(255)

i have never ever used #$FF in 30 years of programing with a pascal dialect... only #FF when writing or checking for data in hex format... but this is the first time that i'm needing/wanting to depict it in a static array as a (end result) string of characters to search for and replace with the StringsReplace routine available in FPC... in the past, i would have written my own but since this one exists, it makes things much easier ;) :)

i will take a look... if it works, i've learned something new since my days of coding with borland pascal ;)

Unknown author
patspiper wrote
On 21/09/13 18:56, wrote:

[...]

Show quoted text 5 lines
> i haven't tried that... my understanding is that #xx depicts the decimal format of the character... > > eg : $FF == #255 It is rather #$FF which is the same as #255, like Chr(255)

this worked, pat... thanks for the pointer!

but i'm still confused as to what # means to indicate... i've always understood it to indicate the decimal value of a raw byte whereas $ indicates the hex value of a raw byte... i haven't found anything showing the use of #$xxx though :/

in any case, this worked and i'm a bit happier :) :) :)

Unknown author
this worked, pat... thanks for the pointer!

oops... i meant Stephano... sorry...

damned webmail drek sucks...

patspiper
to Unknown author: [...] this worked, pat... thanks for the pointer! but i'm still confused as to what #…
Show quoted text 10 lines
On Saturday, September 21, 2013 12:03 PM, patspiper wrote: > On 21/09/13 18:56, wrote: [...] >> i haven't tried that... my understanding is that #xx depicts the decimal > format of the character... >> eg : $FF == #255 > It is rather #$FF which is the same as #255, like Chr(255) this worked, pat... thanks for the pointer! but i'm still confused as to what # means to indicate... i've always understood it to indicate the decimal value of a raw byte whereas $ indicates the hex value of a raw byte... i haven't found anything showing the use of #$xxx though :/

This might help:
http://docwiki.embarcadero.com/RADStudio/XE5/en/Fundamental_Syntactic_Elements

in any case, this worked and i'm a bit happier :) :) :)

:)

Stephano

Sven Barth
to Unknown author: [...] this worked, pat... thanks for the pointer! but i'm still confused as to what #…
Show quoted text 13 lines
On Saturday, September 21, 2013 12:03 PM, patspiper wrote: > On 21/09/13 18:56, wrote: [...] >> i haven't tried that... my understanding is that #xx depicts the decimal > format of the character... >> >> eg : $FF == #255 > It is rather #$FF which is the same as #255, like Chr(255) this worked, pat... thanks for the pointer! but i'm still confused as to what # means to indicate... i've always understood it to indicate the decimal value of a raw byte whereas $ indicates the hex value of a raw byte... i haven't found anything showing the use of #$xxx though :/

'#' indicates a character. This is followed by either a decimal or hexadecimal ('$') value (maybe - in FPC - binary ('%') and octal ('&') values are possible as well).

Regards,
Sven

Unknown author
Sven Barth wrote 22 lines
On 12209201313:38, wrote: > > On Saturday, September 21, 2013 12:03 PM, patspiper wrote: >> On 21/09/13 18:56, wrote: > [...] >>> i haven't tried that... my understanding is that #xx depicts the decimal >> format of the character... >>> >>> eg : $FF == #255 >> It is rather #$FF which is the same as #255, like Chr(255) > > this worked, pat... thanks for the pointer! > > but i'm still confused as to what # means to indicate... i've always understood it to indicate the decimal value of a raw byte whereas $ indicates the hex value of a raw byte... i haven't found anything showing the use of #$xxx though :/ '#' indicates a character. This is followed by either a decimal or hexadecimal ('$') value (maybe - in FPC - binary ('%') and octal ('&') values are possible as well).

ahhh! ok... that makes sense... i had read about FPC being able to use binary and octal as well but only in certain modes... TP and Delphi modes don't allow them IIRC... anyway, i've been in TP/BP for so long that i just thought that # indicated a decimal character where $ indicated the same in hex... granted, this is the first time i've wanted to do this in many years... previously in TP/BP (i've never done anything with delphi) i had to resort to putting in the actual characters which i wanted to bypass this time...

thanks for the information... things have changed in all these years O:)