Negative base numbers: Difference between revisions

Content added Content deleted
(changed driver output for decoding)
(Formatted string spacing on output.)
Line 275: Line 275:
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Text_IO; use Ada.Text_IO;
with Negative_Base_Numbers; use Negative_Base_Numbers;
with Negative_Base_Numbers; use Negative_Base_Numbers;
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;

with Ada.Text_IO; use Ada.Text_IO;
with Negative_Base_Numbers; use Negative_Base_Numbers;
with Ada.Strings.Fixed; use Ada.Strings.Fixed;
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;


Line 283: Line 288:
use long_IO;
use long_IO;


ns : Unbounded_String := Encode_Negative_Base (N, B);
ns : Unbounded_String := Encode_Negative_Base (N, B);
P : Long_Long_Integer;
P : Long_Long_Integer;
Output : String (1 .. 12);


begin
begin
Line 292: Line 298:
Put_Line (" = " & To_String (ns));
Put_Line (" = " & To_String (ns));


Move
(Source => To_String (ns), Target => Output,
Justify => Ada.Strings.Right);
P := Decode_Negative_Base (ns, B);
P := Decode_Negative_Base (ns, B);
Put (To_String(ns));
Put (Output & " decoded in base ");
Put (" decoded in base ");
Put (Item => B, Width => 3);
Put (Item => B, Width => 3);
Put (" = ");
Put (" = ");
Put (Item => P, Width => 1);
Put (Item => P, Width => 1);
New_Line(2);
New_Line (2);
end driver;
end driver;


Line 305: Line 313:
driver (146, -3);
driver (146, -3);
driver (15, -10);
driver (15, -10);
driver (36058, -62);
driver (36_058, -62);
end Main;</lang>
end Main;</lang>
{{out}}
{{out}}
<pre>
<pre>
10 encoded in base -2 = 11110
10 encoded in base -2 = 11110
11110 decoded in base -2 = 10
11110 decoded in base -2 = 10


146 encoded in base -3 = 21102
146 encoded in base -3 = 21102
21102 decoded in base -3 = 146
21102 decoded in base -3 = 146


15 encoded in base -10 = 195
15 encoded in base -10 = 195
195 decoded in base -10 = 15
195 decoded in base -10 = 15


36058 encoded in base -62 = Ada
36058 encoded in base -62 = Ada
Ada decoded in base -62 = 36058</pre>
Ada decoded in base -62 = 36058</pre>


=={{header|ALGOL 68}}==
=={{header|ALGOL 68}}==