Skip to content

Commit

Permalink
refactor: Binary shown with spaces every 4 digits
Browse files Browse the repository at this point in the history
Closes #7
  • Loading branch information
gcarreno committed Mar 11, 2021
1 parent 86a07c3 commit 2e0ef68
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/application/ljv.application.version.pas
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@
interface

const
cVersion = '0.1.9.34';
cVersion = '0.1.9.36';
cVersionMajor = 0;
cVersionMinor = 1;
cVersionRevision = 9;
cVersionBuild = 35;
cVersionBuild = 36;

implementation

Expand Down
27 changes: 25 additions & 2 deletions src/forms/ljv.forms.main.pas
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ TfrmMain = class(TForm)
procedure UpdateTreeFromNode(const ANode: PVirtualNode;
const AJSONData: TJSONData; const APath: String);
procedure ShowValue(const AJSONData: TJSONData);
function MyIntegerToBinary(const AInteger: Int64;
const ADigits: Integer): String;
public

end;
Expand Down Expand Up @@ -924,7 +926,7 @@ procedure TfrmMain.ShowValue(const AJSONData: TJSONData);
edt.Text:= Format('%d', [AJSONData.AsInteger]);
edtFormated.Text:= FormatFloat(cNumberFormatInteger, AJSONData.AsFloat);
edtScientific.Text:= FormatFloat(cNumberFormatFloatScientific, AJSONData.AsFloat);
edtBin.Text:= IntToBin(AJSONData.AsInt64, 32);
edtBin.Text:= MyIntegerToBinary(AJSONData.AsInt64, 32);
edtHex.Text:= IntToHex(AJSONData.AsInteger, 16);
edtBytes.Text:= FormatBytes(AJSONData.AsInteger);
edtDateTime.Text:= FormatDateTime(cDateTimeFormat, UnixToDateTime(AJSONData.AsInteger));
Expand All @@ -933,7 +935,7 @@ procedure TfrmMain.ShowValue(const AJSONData: TJSONData);
edt.Text:= Format('%d', [AJSONData.AsInt64]);
edtFormated.Text:= FormatFloat(cNumberFormatInteger, AJSONData.AsFloat);
edtScientific.Text:= FormatFloat(cNumberFormatFloatScientific, AJSONData.AsFloat);
edtBin.Text:= IntToBin(AJSONData.AsInt64, 64);
edtBin.Text:= MyIntegerToBinary(AJSONData.AsInt64, 64);
edtHex.Text:= IntToHex(AJSONData.AsInt64, 16);
edtBytes.Text:= FormatBytes(AJSONData.AsInt64);
edtDateTime.Text:= FormatDateTime(cDateTimeFormat, UnixToDateTime(AJSONData.AsInt64));
Expand Down Expand Up @@ -989,5 +991,26 @@ procedure TfrmMain.ShowValue(const AJSONData: TJSONData);
end;
end;

function TfrmMain.MyIntegerToBinary(const AInteger: Int64;
const ADigits: Integer): String;
var
str: String;
idx: Integer;
begin
Result:= '';
str:= IntToBin(AInteger, ADigits);
for idx:= 1 to Length(str) do
begin
if (idx mod 4 = 0) and (idx <> Length(str)) then
begin
Result:= ' ' +str[Succ(Length(str)) - idx] + Result;
end
else
begin
Result:= str[Succ(Length(str)) - idx] + Result;
end;
end;
end;

end.

2 changes: 1 addition & 1 deletion src/lazJSONViewer.lpi
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<UseVersionInfo Value="True"/>
<MinorVersionNr Value="1"/>
<RevisionNr Value="9"/>
<BuildNr Value="35"/>
<BuildNr Value="36"/>
<Language Value="0809"/>
</VersionInfo>
<BuildModes Count="3">
Expand Down

0 comments on commit 2e0ef68

Please sign in to comment.