Sign in Join

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

Mailing lists / fpc-devel / 2006-11

Efficient way to inc loop over hexadecimal values

9 messages · 5 people ·

Reply by email Subscribe to this list Your subscription

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

ik

Hi List,

I have two cardinal numbers that represent ranges.

The 10 base value of that two variables are useless and far from having any meaning for my needs.However the hexa number does have meaning after I'm changing the network order (aka big endian).

I can think on many non efficient ways to while loop with inc but not even one way to inc it in an efficient way.

So, I'm looking for an efficient way to loop from left range to right range when the values are in Hexa-decimal.

Thank you for any help on this matter,

Ido

Reply by email

Dominique Leducq
to ik
ik wrote 17 lines
Hi List, I have two cardinal numbers that represent ranges. The 10 base value of that two variables are useless and far from having any meaning for my needs.However the hexa number does have meaning after I'm changing the network order (aka big endian). I can think on many non efficient ways to while loop with inc but not even one way to inc it in an efficient way. So, I'm looking for an efficient way to loop from left range to right range when the values are in Hexa-decimal. Thank you for any help on this matter, Ido

I'm afraid I don't understand your problem. Decimal or hexadecimal are string representation formats, cardinal and integer values are stored and dealt with internally in binary form !
If your values are hexadecimal number stored in strings, why not convert them first to Cardinal ?

Could you perhaps give an example or be more precise ?

Reply by email

ik
to Dominique Leducq
Dominique Leducq wrote 26 lines
ik a écrit : > Hi List, > > I have two cardinal numbers that represent ranges. > > The 10 base value of that two variables are useless and far from > having any meaning for my needs.However the hexa number does have > meaning after I'm changing the network order (aka big endian). > > I can think on many non efficient ways to while loop with inc but not > even one way to inc it in an efficient way. > > So, I'm looking for an efficient way to loop from left range to right > range when the values are in Hexa-decimal. > > Thank you for any help on this matter, > > Ido I'm afraid I don't understand your problem. Decimal or hexadecimal are string representation formats, cardinal and integer values are stored and dealt with internally in binary form ! If your values are hexadecimal number stored in strings, why not convert them first to Cardinal ? Could you perhaps give an example or be more precise ?

OK, I have (for this example, taken from my own testing) the following numbers: Decima numbers: a = 3616538624 b = 3616669696
The hexa values are: a = D7900000 b = D7920000

As you can see the range differences between the decimals are way bigger then the hexa values.

The thing is that the hexa numbers represent chars of a UTF-8 encoding. D790 is the char "א".
(http://www.utf8-chartable.de/unicode-utf8-table.pl look for Hebrew).

So I wish to run on the range between a..b (in Hexa) and to have all of the values in between.

There are many bad ways to do it such as:

while (not hexStr (i) = b) do
 begin
  ...
  inc (i)
  ....
 end;

This exampel does not cover all the possible values I might need.

So, I'm looking for a much faster and smarter way to do it, rather the bad way above.

Ido

Reply by email

Vincent Snijders
to ik
ik wrote 35 lines
On 11/22/06, Dominique Leducq wrote: > ik a écrit : > > Hi List, > > > > I have two cardinal numbers that represent ranges. > > > > The 10 base value of that two variables are useless and far from > > having any meaning for my needs.However the hexa number does have > > meaning after I'm changing the network order (aka big endian). > > > > I can think on many non efficient ways to while loop with inc but not > > even one way to inc it in an efficient way. > > > > So, I'm looking for an efficient way to loop from left range to right > > range when the values are in Hexa-decimal. > > > > Thank you for any help on this matter, > > > > Ido > > I'm afraid I don't understand your problem. Decimal or hexadecimal are > string representation formats, cardinal and integer values are stored > and dealt with internally in binary form ! > If your values are hexadecimal number stored in strings, why not convert > them first to Cardinal ? > > Could you perhaps give an example or be more precise ? OK, I have (for this example, taken from my own testing) the following numbers: Decima numbers: a = 3616538624 b = 3616669696 The hexa values are: a = D7900000 b = D7920000 As you can see the range differences between the decimals are way bigger then the hexa values.

The numerical difference is the same. The difference seems larger if you are speaking about the string represetations of these 32 bits numbers ('3616538624','3616669696') and ('D7900000','D7920000 ')

Show quoted text 18 lines
The thing is that the hexa numbers represent chars of a UTF-8 encoding. D790 is the char "א". (http://www.utf8-chartable.de/unicode-utf8-table.pl look for Hebrew). So I wish to run on the range between a..b (in Hexa) and to have all of the values in between. There are many bad ways to do it such as: while (not hexStr (i) = b) do begin ... inc (i) .... end; This exampel does not cover all the possible values I might need.

Why not?

So, I'm looking for a much faster and smarter way to do it, rather the bad way above.

Do you want to operate on strings or on numbers or on somthing else?

Vincent

Reply by email

Пётр Косаревский
('3616538624','3616669696') and ('D7900000','D7920000 ')

If I get it right, you can translate borders (a and b: strings in some formats) to numbers (x and y) and do something like

for i:=x to y do
 begin
 // many bad and good things
 end;

If the numbers are supposed to be in some special order (e.g. mix of 1-4 bytes long UTF-8 codes), you are too vague.

Reply by email

Joao Morais
to ik: OK, I have (for this example, taken from my own testing) the following numbers: Decima…
ik wrote 56 lines
On 11/22/06, Dominique Leducq wrote: > ik a écrit : > > Hi List, > > > > I have two cardinal numbers that represent ranges. > > > > The 10 base value of that two variables are useless and far from > > having any meaning for my needs.However the hexa number does have > > meaning after I'm changing the network order (aka big endian). > > > > I can think on many non efficient ways to while loop with inc but not > > even one way to inc it in an efficient way. > > > > So, I'm looking for an efficient way to loop from left range to right > > range when the values are in Hexa-decimal. > > > > Thank you for any help on this matter, > > > > Ido > > I'm afraid I don't understand your problem. Decimal or hexadecimal are > string representation formats, cardinal and integer values are stored > and dealt with internally in binary form ! > If your values are hexadecimal number stored in strings, why not convert > them first to Cardinal ? > > Could you perhaps give an example or be more precise ? OK, I have (for this example, taken from my own testing) the following numbers: Decima numbers: a = 3616538624 b = 3616669696 The hexa values are: a = D7900000 b = D7920000 As you can see the range differences between the decimals are way bigger then the hexa values. The thing is that the hexa numbers represent chars of a UTF-8 encoding. D790 is the char "א". (http://www.utf8-chartable.de/unicode-utf8-table.pl look for Hebrew). So I wish to run on the range between a..b (in Hexa) and to have all of the values in between. There are many bad ways to do it such as: while (not hexStr (i) = b) do begin ... inc (i) .... end; This exampel does not cover all the possible values I might need. So, I'm looking for a much faster and smarter way to do it, rather the bad way above.

Something like this?

for I := $D790 to $D792 do
   YourValue := I * $10000;

Otherwise, if I didn't get what you mean, perhaps you can use some boolean arithmetic.

Joao Morais

Reply by email

ik
to Vincent Snijders: The numerical difference is the same. The difference seems larger if you are speaking…
Vincent Snijders wrote 40 lines
ik schreef: > On 11/22/06, Dominique Leducq wrote: >> ik a écrit : >> > Hi List, >> > >> > I have two cardinal numbers that represent ranges. >> > >> > The 10 base value of that two variables are useless and far from >> > having any meaning for my needs.However the hexa number does have >> > meaning after I'm changing the network order (aka big endian). >> > >> > I can think on many non efficient ways to while loop with inc but not >> > even one way to inc it in an efficient way. >> > >> > So, I'm looking for an efficient way to loop from left range to right >> > range when the values are in Hexa-decimal. >> > >> > Thank you for any help on this matter, >> > >> > Ido >> >> I'm afraid I don't understand your problem. Decimal or hexadecimal are >> string representation formats, cardinal and integer values are stored >> and dealt with internally in binary form ! >> If your values are hexadecimal number stored in strings, why not convert >> them first to Cardinal ? >> >> Could you perhaps give an example or be more precise ? > > OK, I have (for this example, taken from my own testing) the following > numbers: > Decima numbers: a = 3616538624 b = 3616669696 > The hexa values are: a = D7900000 b = D7920000 > > As you can see the range differences between the decimals are way > bigger then the hexa values. The numerical difference is the same. The difference seems larger if you are speaking about the string represetations of these 32 bits numbers ('3616538624','3616669696') and ('D7900000','D7920000 ')

But I need the range of 4 numbers and not the range of handrands of thousands.

Show quoted text 21 lines
> > The thing is that the hexa numbers represent chars of a UTF-8 > encoding. D790 is the char "א". > (http://www.utf8-chartable.de/unicode-utf8-table.pl look for Hebrew). > > So I wish to run on the range between a..b (in Hexa) and to have all > of the values in between. > > There are many bad ways to do it such as: > > while (not hexStr (i) = b) do > begin > ... > inc (i) > .... > end; > > This exampel does not cover all the possible values I might need. Why not?

It seems to be good only for "basic" ranges... I'm creating a function that you can give a start range and end range, and it return all of the chars on that range. so I do not know if I'll place the first 97 letter up to the FFFF letter, that this loop will work well, or fast enough.

Show quoted text 6 lines
> > So, I'm looking for a much faster and smarter way to do it, rather the > bad way above. Do you want to operate on strings or on numbers or on somthing else?

I prefer numeric handing then string handling.

Vincent

Ido

Reply by email

Dominique Leducq
to ik
Show quoted text 43 lines
On 11/22/06, Vincent Snijders wrote: > ik schreef: > > On 11/22/06, Dominique Leducq wrote: > >> ik a écrit : > >> > Hi List, > >> > > >> > I have two cardinal numbers that represent ranges. > >> > > >> > The 10 base value of that two variables are useless and far from > >> > having any meaning for my needs.However the hexa number does have > >> > meaning after I'm changing the network order (aka big endian). > >> > > >> > I can think on many non efficient ways to while loop with inc but not > >> > even one way to inc it in an efficient way. > >> > > >> > So, I'm looking for an efficient way to loop from left range to right > >> > range when the values are in Hexa-decimal. > >> > > >> > Thank you for any help on this matter, > >> > > >> > Ido > >> > >> I'm afraid I don't understand your problem. Decimal or hexadecimal are > >> string representation formats, cardinal and integer values are stored > >> and dealt with internally in binary form ! > >> If your values are hexadecimal number stored in strings, why not convert > >> them first to Cardinal ? > >> > >> Could you perhaps give an example or be more precise ? > > > > OK, I have (for this example, taken from my own testing) the following > > numbers: > > Decima numbers: a = 3616538624 b = 3616669696 > > The hexa values are: a = D7900000 b = D7920000 > > > > As you can see the range differences between the decimals are way > > bigger then the hexa values. > > The numerical difference is the same. The difference seems larger if you are > speaking about the string represetations of these 32 bits numbers > ('3616538624','3616669696') and ('D7900000',' ') But I need the range of 4 numbers and not the range of handrands of thousands.

There are far more than 4 numbers between D7900000 and D7920000, and as much as between 3616538624 and 3616669696. Or what are you calling numbers ? Digits ?
I suggest you give us a sample of what values your loop counter may take, and in what order.

Show quoted text 44 lines
> > > > > The thing is that the hexa numbers represent chars of a UTF-8 > > encoding. D790 is the char "א". > > (http://www.utf8-chartable.de/unicode-utf8-table.pl look for Hebrew). > > > > So I wish to run on the range between a..b (in Hexa) and to have all > > of the values in between. > > > > There are many bad ways to do it such as: > > > > while (not hexStr (i) = b) do > > begin > > ... > > inc (i) > > .... > > end; > > > > This exampel does not cover all the possible values I might need. > > Why not? It seems to be good only for "basic" ranges... I'm creating a function that you can give a start range and end range, and it return all of the chars on that range. so I do not know if I'll place the first 97 letter up to the FFFF letter, that this loop will work well, or fast enough. > > > > > So, I'm looking for a much faster and smarter way to do it, rather the > > bad way above. > > Do you want to operate on strings or on numbers or on somthing else? I prefer numeric handing then string handling. > > Vincent Ido -- http://ik.homelinux.org/

Reply by email

ik
to Dominique Leducq
Dominique Leducq wrote 48 lines
On Wed, 22 Nov 2006 16:56:04 +0200 ik wrote: > On 11/22/06, Vincent Snijders wrote: > > ik schreef: > > > On 11/22/06, Dominique Leducq wrote: > > >> ik a écrit : > > >> > Hi List, > > >> > > > >> > I have two cardinal numbers that represent ranges. > > >> > > > >> > The 10 base value of that two variables are useless and far from > > >> > having any meaning for my needs.However the hexa number does have > > >> > meaning after I'm changing the network order (aka big endian). > > >> > > > >> > I can think on many non efficient ways to while loop with inc but not > > >> > even one way to inc it in an efficient way. > > >> > > > >> > So, I'm looking for an efficient way to loop from left range to right > > >> > range when the values are in Hexa-decimal. > > >> > > > >> > Thank you for any help on this matter, > > >> > > > >> > Ido > > >> > > >> I'm afraid I don't understand your problem. Decimal or hexadecimal are > > >> string representation formats, cardinal and integer values are stored > > >> and dealt with internally in binary form ! > > >> If your values are hexadecimal number stored in strings, why not convert > > >> them first to Cardinal ? > > >> > > >> Could you perhaps give an example or be more precise ? > > > > > > OK, I have (for this example, taken from my own testing) the following > > > numbers: > > > Decima numbers: a = 3616538624 b = 3616669696 > > > The hexa values are: a = D7900000 b = D7920000 > > > > > > As you can see the range differences between the decimals are way > > > bigger then the hexa values. > > > > The numerical difference is the same. The difference seems larger if you are > > speaking about the string represetations of these 32 bits numbers > > ('3616538624','3616669696') and ('D7900000',' ') > > But I need the range of 4 numbers and not the range of handrands of thousands. There are far more than 4 numbers between D7900000 and D7920000, and as much as between 3616538624 and 3616669696.

/me Blush
I can see that now... I need to do something with my eyes.... :)

Finally I understand what I did wrong, and how to solve this ... Thank you for pointing the obvious (not for me :( ) for me :)

/me going to crawl now to some place ...

Show quoted text 48 lines
Or what are you calling numbers ? Digits ? I suggest you give us a sample of what values your loop counter may take, and in what order. > > > > > > > > > The thing is that the hexa numbers represent chars of a UTF-8 > > > encoding. D790 is the char "א". > > > (http://www.utf8-chartable.de/unicode-utf8-table.pl look for Hebrew). > > > > > > So I wish to run on the range between a..b (in Hexa) and to have all > > > of the values in between. > > > > > > There are many bad ways to do it such as: > > > > > > while (not hexStr (i) = b) do > > > begin > > > ... > > > inc (i) > > > .... > > > end; > > > > > > This exampel does not cover all the possible values I might need. > > > > Why not? > > It seems to be good only for "basic" ranges... I'm creating a function > that you can give a start range and end range, and it return all of > the chars on that range. so I do not know if I'll place the first 97 > letter up to the FFFF letter, that this loop will work well, or fast > enough. > > > > > > > > > So, I'm looking for a much faster and smarter way to do it, rather the > > > bad way above. > > > > Do you want to operate on strings or on numbers or on somthing else? > > I prefer numeric handing then string handling. > > > > > Vincent > > Ido > -- > http://ik.homelinux.org/

Ido

Reply by email