-3

I have a problem when I input numbers 2,5,7 the results are ok and when I input numbers 1,3,4,6 the results don't match.

define variable oct as character.
define variable l-oct as integer.
define variable oktal as integer.
define variable l-oktal  as integer.
define variable count as integer.
define variable i as integer.
define variable bin as character.
define variable bin2 as character.

end.

do i = length(bin) to 1 by -1:
  bin2 = bin2 + substring(bin, i, 1).
end.

display bin2 with frame a down.

1 Answers1

1

Your if else if train is missing an else if. An if else if train is usually better served by a case statement.

Additionally, you are first constructing a back to front in groups of three digits binary string and subsequently reversing this at the end per digit.

So where octal 1 becomes binary 001 you are flipping this to 100. Instead of flipping afterwards, concatenate your string correctly to start with, so replace all occurrences of:

bin = bin + 'xxx'

with:

bin = 'xxx' + bin

Stefan Drissen
  • 3,266
  • 1
  • 13
  • 21