Recent

Author Topic: can IntToHex digits be selected ?  (Read 1726 times)

440bx

  • Hero Member
  • *****
  • Posts: 4029
can IntToHex digits be selected ?
« 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 ?

Thank you for your help.
(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

dseligo

  • Hero Member
  • *****
  • Posts: 1221
Re: can IntToHex digits be selected ?
« Reply #1 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.

MarkMLl

  • Hero Member
  • *****
  • Posts: 6686
Re: can IntToHex digits be selected ?
« Reply #2 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
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

440bx

  • Hero Member
  • *****
  • Posts: 4029
Re: can IntToHex digits be selected ?
« Reply #3 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.
(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

jamie

  • Hero Member
  • *****
  • Posts: 6130
Re: can IntToHex digits be selected ?
« Reply #4 on: April 02, 2021, 10:45:29 pm »
InttoStr(?, ?).ToLower;

is that what you were looking fer ?  :o
The only true wisdom is knowing you know nothing

MarkMLl

  • Hero Member
  • *****
  • Posts: 6686
Re: can IntToHex digits be selected ?
« Reply #5 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
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

jamie

  • Hero Member
  • *****
  • Posts: 6130
Re: can IntToHex digits be selected ?
« Reply #6 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.

The only true wisdom is knowing you know nothing

dseligo

  • Hero Member
  • *****
  • Posts: 1221
Re: can IntToHex digits be selected ?
« Reply #7 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"?

jamie

  • Hero Member
  • *****
  • Posts: 6130
Re: can IntToHex digits be selected ?
« Reply #8 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)
« Last Edit: April 03, 2021, 12:31:35 am by jamie »
The only true wisdom is knowing you know nothing

 

TinyPortal © 2005-2018