# Lazarus

## Free Pascal => Beginners => Topic started by: 440bx on April 02, 2021, 09:51:18 pm

Title: can IntToHex digits be selected ?
Post by: 440bx on April 02, 2021, 09:51:18 pm
Hello,

When using IntToHex, it seems to always use the uppercased A-F digits.

My question is: is there a way to cause IntToHex to use lowercase digits, e.g, abc0def0 ?

Title: Re: can IntToHex digits be selected ?
Post by: dseligo on April 02, 2021, 10:10:10 pm
Array for converting is defined as (so it's fixed case):
Code: Pascal  [Select][+][-]
1. const
2.    HexDigits: array[0..15] of char = '0123456789ABCDEF';
(this is in sysstr.inc).

You can use Lowercase function or copy function IntToHex and adapt it.
Title: Re: can IntToHex digits be selected ?
Post by: MarkMLl on April 02, 2021, 10:11:30 pm
Just use LowerCase() on it.

I think this is a cultural thing: those of us who've got here via Teletypes and the H suffix tend to use uppercase, those with a unix bent and the 0x prefix use lowercase. I admit that I've moved from one to the other over the last few years.

MarkMLl
Title: Re: can IntToHex digits be selected ?
Post by: 440bx on April 02, 2021, 10:21:13 pm
Thank you both for the replies.

I'll use Lowercase() as you both suggested when I need/prefer lowercase digits.
Title: Re: can IntToHex digits be selected ?
Post by: jamie on April 02, 2021, 10:45:29 pm
InttoStr(?, ?).ToLower;

is that what you were looking fer ?  :o
Title: Re: can IntToHex digits be selected ?
Post by: MarkMLl on April 02, 2021, 10:48:46 pm
InttoStr(?, ?).ToLower;

is that what you were looking fer ?  :o

You do know what hex is, don't you?

MarkMLl
Title: Re: can IntToHex digits be selected ?
Post by: jamie on April 02, 2021, 11:23:13 pm
LOL really, are you kidding me?

That was my first binary coding machine, a numerical entry key pad..

This place is like the local pub on the weekends.

Title: Re: can IntToHex digits be selected ?
Post by: dseligo on April 02, 2021, 11:49:24 pm
LOL really, are you kidding me?
You have lapsus in your response: you wrote InttoStr instead of IntToHex, that's the reason for MarkMLI's response.

I am interested why do you think ".ToString" is better than "LowerCase"?
Title: Re: can IntToHex digits be selected ?
Post by: jamie on April 03, 2021, 12:11:32 am
LOL, you are correct sir

Excuse me!

I must be the one that is at the pub atm!
:o
btw
feast your eyes this I just whipped up in some code..
Code: Pascal  [Select][+][-]
1. function TIGESFieldHelper.ToInteger: integer;
2. begin
3.   Result := StrToInt(DefaultString(String(Self).Trim,'0'));
4. end;
5.
The helper is on a Array of char of 8 chars long and there is a number that is right justified so I put the compiler to work..
This works well in Delphi , I just tested it here and it works well in Fpc too, it appears..

most likely why I got the StrtoHex wrong here, my mind is elsewhere.

btw, it would be nice if we had a "DefaultString" function.  As you can see it could be used in so many places in code to replace existing code, this will reduce the code base..

don't worry, it seems Delphi does not have the "DefaultString" function either.. oh well..
have fun, drinks on me, You may have a hard time locating me to pay for it though !  :D

P.S.
I know I can use the StrToIntDef but I am just hinting for maybe some support on getting the "defaultString" added  8)