Skip to content

Instantly share code, notes, and snippets.

@artem78
Last active December 1, 2025 10:42
Show Gist options
  • Select an option

  • Save artem78/46a9062b06b2da2ebc584281a8ac0466 to your computer and use it in GitHub Desktop.

Select an option

Save artem78/46a9062b06b2da2ebc584281a8ac0466 to your computer and use it in GitHub Desktop.
{$Mode objfpc}
{$H+}
{ HEX <=> Pascal converter}
{ #FA8072 --> $7280FA
$7280FA --> #FA8072 }
{ try online: https://onecompiler.com/pascal/4469yrb44 }
program flipcolor;
uses sysutils,Classes, StrUtils;
function FlipColor(AColor: Integer): Integer;
var
a,b,c: Byte;
begin
//a:=AColor mod $100;
a:=AColor div $10000;
b:=(AColor - A * $10000) div $100;
//c:=AColor div $10000;
c:= AColor mod $100;
Result:=a+b*$100+c*$10000;
(*WriteLn('A:', IntToHex(a));
WriteLn('B:', IntToHex(b));
WriteLn('C:', IntToHex(c));
WriteLn(IntToHex(AColor), ' -> ', IntToHex(Result)); *)
end;
var
s,s2: string;
FromPas: Boolean;
color, color2: Integer;
begin
Write{Ln}('Введите цвет: ');
ReadLn(s);
///
//s:='0Xabcdef';
///
s := Trim(s);
FromPas := s.StartsWith('$');
if s.StartsWith('$') or s.StartsWith('#') then
//Delete(s, 2, Length(s) - 1);
s := s.Substring(1)
else if s.StartsWith('0x', True) then
s := s.Substring(2);
//WriteLn(s);
try
color:=Hex2Dec(s);
except
WriteLn('Ошибка ввода!');
end;
color2:=FlipColor(color);
s2:=IntToHex(color2, 6);
if FromPas then
s2.Insert(0, '#')
else
s2.Insert(0, '$');
WriteLn('Преобразовано в ', s2);
end.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment