I’ve been reading the documentation for the Convert
class in RTL, hoping to see the .NET Convert.ToInt64(string s, int base)
method but I can’t find an equivalent.
Can anyone suggest a cross-platform way to take a binary string (e.g: 00110
) and convert it to an integer?
mh
(marc hoffman)
June 7, 2020, 10:09pm
2
garry.pettet:
I’ve been reading the documentation for the Convert
class in RTL, hoping to see the .NET Convert.ToInt64(string s, int base)
method but I can’t find an equivalent.
Can anyone suggest a cross-platform way to take a binary string (e.g: 00110
) and convert it to an integer?
I don’t think we have one; I’ll look at adding a (Try)ToInt64 overload that takes a base, as well.
mh
(marc hoffman)
June 7, 2020, 10:33pm
3
I’ve pushed a native Convert.TryBinaryStringToUInt64
now. Only did minimal testing, but these succeed so I’m fairly;y confident its good:
method TestBinary;
begin
Check.AreEqual(Convert.TryBinaryStringToUInt64("1x"), nil);
Check.AreEqual(Convert.TryBinaryStringToUInt64("1"), 1);
Check.AreEqual(Convert.TryBinaryStringToUInt64("10"), 2);
Check.AreEqual(Convert.TryBinaryStringToUInt64("100"), 4);
Check.AreEqual(Convert.TryBinaryStringToUInt64("1001"), 9);
end;
1 Like
mh
(marc hoffman)
June 28, 2020, 1:29pm
6
I’ll make sure we run an update this week; these docs are generated automatically from the binaries metadata.
1 Like