微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

obin 转换数字?

如何解决obin 转换数字?

八进制数到二进制数。

我想将此代码转换为八进制到二进制如何..???

帮帮我。

define variable bin as integer.
define variable dec as integer.

set dec label "Masukkan angka desimal" with side-labels.

repeat:
    bin = dec modulo 2.
    dec = dec / 2.
    if bin = 1 then
        dec = dec - 1.
    else if dec < 1 then
        quit.
    display bin dec with frame a down.
end.

解决方法

/* oct2bin.p
 *
 */

function oct2bin returns character ( input octalString as character ):

  define variable i      as integer   no-undo.
  define variable n      as integer   no-undo.
  define variable c      as character no-undo.
  define variable result as character no-undo.

  n = length( octalString ).

  if n < 2 or substring( octalString,1,1 ) <> "~\" then        /* a valid octalString begins with "\"                                */
    do:
      message "valid octal strings must begin with ~\".
      result = ?.
    end.
   else
    do i = 2 to n:

      c = substring( octalString,i,1 ).

      if asc( c ) < 48 or asc( c ) > 55 then                        /* a valid octalString only contains the digits 0 thru 7        */
        do:
          message c "is not a valid numeric character".
          result = ?.
          leave.
        end.

      case c:
        when "0" then result = result + "000".
        when "1" then result = result + "001".
        when "2" then result = result + "010".
        when "3" then result = result + "011".
        when "4" then result = result + "100".
        when "5" then result = result + "101".
        when "6" then result = result + "110".
        when "7" then result = result + "111".
      end.

      /* message octalString n c result.    */
      /* pause.                             */

    end.

  return result.

end.

    
define variable inputField as character no-undo.

do while true:
  update inputField.
  display oct2bin( inputField ).
end.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。