Hi Jeff;
After going back and exhaustively reviewing the AdaCore Learning Introduction sections on Strings and Arrays, I determined that I was not slicing with the correct syntax for what I wanted to obtain, it seems that I was slicing built-in whitespace, not the digits I was looking for. So I am now extracting the two-digit slice using (2 .. 3) rather than (1 .. 2) and I am now obtaining the desired output. What I was trying to do was to obtain the slice from the string on the fly, not first saving the string to a variable.
This is what I have now (which works great):
---------------------------------------------------------------------------
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;
with Ada.Command_Line; use Ada.Command_Line;
with Ada.Numerics.Big_Numbers.Big_Integers; use Ada.Numerics.Big_Numbers.Big_Integers;
procedure Powers_Of_2_With_Leading_Digits_Of_12 is
Max : Positive := Integer'Value (Argument (1));
Powers_of_2 : Big_Positive := 1;
begin
for I in 1 .. Max loop
Powers_of_2 := Powers_of_2 * To_Big_Integer (2);
if I >= 4 then
declare
Powers_of_2_in_String_Format : String := To_String (Powers_of_2);
First_Pair_of_String_Digits : String := Powers_of_2_in_String_Format (2 .. 3);
begin
if First_Pair_of_String_Digits = "12" then
Put ("2^");
Put (I, 0);
Put_Line (To_String (Powers_of_2));
end if;
end; -- declare
end if;
end loop;
end Powers_Of_2_With_Leading_Digits_Of_12;
---------------------------------------------------------------------------
Now I can generalize this to more closely match the task requirements.
I think I tried to incorrectly create the slice from the To_String output directly without creating the variable in which to store the slice, which then requires the declare block.
Thanks,
Ken