Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Pascal to C# Convert

Pascal to C# Convert

Scheduled Pinned Locked Moved C#
csharpdelphidata-structurestutorial
9 Posts 6 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    Pavlex4
    wrote on last edited by
    #1

    How to convert this pascal code in C# :

    uses crt;
    var najbl:int64;
    u,pok,zad,a:longint;
    l:integer;
    niz:array[1..946686] of int64;
    uzet:array[1..6] of boolean;
    w:string;
    lpl:boolean;
    function abs(x:int64):int64;
    begin
    if x>0 then abs:=x
    else abs:=-x;
    end;
    function num2str(y:integer):string;
    begin
    num2str:='';
    repeat
    num2str:=chr(y mod 10+48)+num2str;
    y:=y div 10
    until y=0;
    end;
    procedure inc_uzet;
    var ss:byte;
    begin
    for ss:=1 to 6 do
    uzet[ss]:=false;
    end;
    procedure oznaci_po_redu(s:integer);
    begin
    l:=0;
    while (s>0) do
    begin
    inc(l);
    if not(uzet[l]) then dec(s);
    end;
    uzet[l]:=true;
    end;
    procedure dekodiraj(i:longint);
    begin
    if i<7 then uzet[i]:=true
    else if i<127 then begin
    dekodiraj((i-7) div 4 div 5 + 1);
    oznaci_po_redu((i-7) div 4 - (i-7) div 4 div 5 * 5 + 1);
    end
    else if i<2047 then begin
    dekodiraj((i-127) div 4 div 4 + 7);
    oznaci_po_redu((i-127) div 4 - (i-127) div 4 div 4 * 4 + 1);
    end
    else if i<25087 then begin
    dekodiraj((i-2047) div 4 div 3 + 127);
    oznaci_po_redu((i-2047) div 4 - (i-2047) div 4 div 3 * 3 + 1);
    end
    else if i<209407 then begin
    dekodiraj((i-25087) div 4 div 2 + 2047);
    oznaci_po_redu((i-25087) div 4 - (i-25087) div 4 div 2 * 2 + 1);
    end
    else begin
    dekodiraj((i-209407)div 4 + 25087);
    oznaci_po_redu(1);
    end;
    end;
    procedure dekodiraj1(i:longint);
    var a:longint;
    begin
    if i<7 then begin
    uzet[i]:=true;
    w:=w+num2str(niz[i]);
    lpl:=false;
    end
    else begin
    if i<127 then begin
    a:=(i-7) div 4 div 5 + 1;
    dekodiraj1(a);
    oznaci_po_redu((i-7) div 4 - 5*(a-1)+1);
    end
    else if i<2047 then begin
    a:=(i-127) div 4 div 4 + 7;
    dekodiraj1(a);
    oznaci_po_redu((i-127) div 4 - 4*(a-7)+1);

    Richard DeemingR OriginalGriffO L 3 Replies Last reply
    0
    • P Pavlex4

      How to convert this pascal code in C# :

      uses crt;
      var najbl:int64;
      u,pok,zad,a:longint;
      l:integer;
      niz:array[1..946686] of int64;
      uzet:array[1..6] of boolean;
      w:string;
      lpl:boolean;
      function abs(x:int64):int64;
      begin
      if x>0 then abs:=x
      else abs:=-x;
      end;
      function num2str(y:integer):string;
      begin
      num2str:='';
      repeat
      num2str:=chr(y mod 10+48)+num2str;
      y:=y div 10
      until y=0;
      end;
      procedure inc_uzet;
      var ss:byte;
      begin
      for ss:=1 to 6 do
      uzet[ss]:=false;
      end;
      procedure oznaci_po_redu(s:integer);
      begin
      l:=0;
      while (s>0) do
      begin
      inc(l);
      if not(uzet[l]) then dec(s);
      end;
      uzet[l]:=true;
      end;
      procedure dekodiraj(i:longint);
      begin
      if i<7 then uzet[i]:=true
      else if i<127 then begin
      dekodiraj((i-7) div 4 div 5 + 1);
      oznaci_po_redu((i-7) div 4 - (i-7) div 4 div 5 * 5 + 1);
      end
      else if i<2047 then begin
      dekodiraj((i-127) div 4 div 4 + 7);
      oznaci_po_redu((i-127) div 4 - (i-127) div 4 div 4 * 4 + 1);
      end
      else if i<25087 then begin
      dekodiraj((i-2047) div 4 div 3 + 127);
      oznaci_po_redu((i-2047) div 4 - (i-2047) div 4 div 3 * 3 + 1);
      end
      else if i<209407 then begin
      dekodiraj((i-25087) div 4 div 2 + 2047);
      oznaci_po_redu((i-25087) div 4 - (i-25087) div 4 div 2 * 2 + 1);
      end
      else begin
      dekodiraj((i-209407)div 4 + 25087);
      oznaci_po_redu(1);
      end;
      end;
      procedure dekodiraj1(i:longint);
      var a:longint;
      begin
      if i<7 then begin
      uzet[i]:=true;
      w:=w+num2str(niz[i]);
      lpl:=false;
      end
      else begin
      if i<127 then begin
      a:=(i-7) div 4 div 5 + 1;
      dekodiraj1(a);
      oznaci_po_redu((i-7) div 4 - 5*(a-1)+1);
      end
      else if i<2047 then begin
      a:=(i-127) div 4 div 4 + 7;
      dekodiraj1(a);
      oznaci_po_redu((i-127) div 4 - 4*(a-7)+1);

      Richard DeemingR Offline
      Richard DeemingR Offline
      Richard Deeming
      wrote on last edited by
      #2

      LMGTFY[^] Seriously? You dump 743 lines of Pascal in a question, and expect someone here to convert it for you? :wtf: Either find a tool to do the conversion, or convert it yourself. If you get stuck with A SPECIFIC PART of the conversion, someone here will probably be able to help. But nobody is going to convert the whole program for you!


      "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

      "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

      P 1 Reply Last reply
      0
      • P Pavlex4

        How to convert this pascal code in C# :

        uses crt;
        var najbl:int64;
        u,pok,zad,a:longint;
        l:integer;
        niz:array[1..946686] of int64;
        uzet:array[1..6] of boolean;
        w:string;
        lpl:boolean;
        function abs(x:int64):int64;
        begin
        if x>0 then abs:=x
        else abs:=-x;
        end;
        function num2str(y:integer):string;
        begin
        num2str:='';
        repeat
        num2str:=chr(y mod 10+48)+num2str;
        y:=y div 10
        until y=0;
        end;
        procedure inc_uzet;
        var ss:byte;
        begin
        for ss:=1 to 6 do
        uzet[ss]:=false;
        end;
        procedure oznaci_po_redu(s:integer);
        begin
        l:=0;
        while (s>0) do
        begin
        inc(l);
        if not(uzet[l]) then dec(s);
        end;
        uzet[l]:=true;
        end;
        procedure dekodiraj(i:longint);
        begin
        if i<7 then uzet[i]:=true
        else if i<127 then begin
        dekodiraj((i-7) div 4 div 5 + 1);
        oznaci_po_redu((i-7) div 4 - (i-7) div 4 div 5 * 5 + 1);
        end
        else if i<2047 then begin
        dekodiraj((i-127) div 4 div 4 + 7);
        oznaci_po_redu((i-127) div 4 - (i-127) div 4 div 4 * 4 + 1);
        end
        else if i<25087 then begin
        dekodiraj((i-2047) div 4 div 3 + 127);
        oznaci_po_redu((i-2047) div 4 - (i-2047) div 4 div 3 * 3 + 1);
        end
        else if i<209407 then begin
        dekodiraj((i-25087) div 4 div 2 + 2047);
        oznaci_po_redu((i-25087) div 4 - (i-25087) div 4 div 2 * 2 + 1);
        end
        else begin
        dekodiraj((i-209407)div 4 + 25087);
        oznaci_po_redu(1);
        end;
        end;
        procedure dekodiraj1(i:longint);
        var a:longint;
        begin
        if i<7 then begin
        uzet[i]:=true;
        w:=w+num2str(niz[i]);
        lpl:=false;
        end
        else begin
        if i<127 then begin
        a:=(i-7) div 4 div 5 + 1;
        dekodiraj1(a);
        oznaci_po_redu((i-7) div 4 - 5*(a-1)+1);
        end
        else if i<2047 then begin
        a:=(i-127) div 4 div 4 + 7;
        dekodiraj1(a);
        oznaci_po_redu((i-127) div 4 - 4*(a-7)+1);

        OriginalGriffO Offline
        OriginalGriffO Offline
        OriginalGriff
        wrote on last edited by
        #3

        Don't. It may seem to fit the bill for you homework question, but blindly converting code from one language to another does not normally produce code that is any good in the destination language. Pascal is not C#, and does not use the same underlying framework. If you must, understand how it's doing whatever it is doing, and adapt the algorithms to C# in a new application. But don't try and get it translated and assume you will get a good grade: you won't. And that's ignoring that your tutor is aware this site exists and will almost certainly spot the plagiarism... Besides: that code is very, very poor - it looks like it was written by three chimpanzees who never actually spoke to each other ...

        Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...

        "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
        "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

        P L 2 Replies Last reply
        0
        • Richard DeemingR Richard Deeming

          LMGTFY[^] Seriously? You dump 743 lines of Pascal in a question, and expect someone here to convert it for you? :wtf: Either find a tool to do the conversion, or convert it yourself. If you get stuck with A SPECIFIC PART of the conversion, someone here will probably be able to help. But nobody is going to convert the whole program for you!


          "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

          P Offline
          P Offline
          Pavlex4
          wrote on last edited by
          #4

          I found this tool but I don't know how to use it: Convert Delphi to C# download | SourceForge.net[^]

          1 Reply Last reply
          0
          • OriginalGriffO OriginalGriff

            Don't. It may seem to fit the bill for you homework question, but blindly converting code from one language to another does not normally produce code that is any good in the destination language. Pascal is not C#, and does not use the same underlying framework. If you must, understand how it's doing whatever it is doing, and adapt the algorithms to C# in a new application. But don't try and get it translated and assume you will get a good grade: you won't. And that's ignoring that your tutor is aware this site exists and will almost certainly spot the plagiarism... Besides: that code is very, very poor - it looks like it was written by three chimpanzees who never actually spoke to each other ...

            Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...

            P Offline
            P Offline
            PIEBALDconsult
            wrote on last edited by
            #5

            And, as everyone knows, Pascal code must be in all caps. :-D

            1 Reply Last reply
            0
            • OriginalGriffO OriginalGriff

              Don't. It may seem to fit the bill for you homework question, but blindly converting code from one language to another does not normally produce code that is any good in the destination language. Pascal is not C#, and does not use the same underlying framework. If you must, understand how it's doing whatever it is doing, and adapt the algorithms to C# in a new application. But don't try and get it translated and assume you will get a good grade: you won't. And that's ignoring that your tutor is aware this site exists and will almost certainly spot the plagiarism... Besides: that code is very, very poor - it looks like it was written by three chimpanzees who never actually spoke to each other ...

              Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              OriginalGriff wrote:

              written by three chimpanzees

              Chimpanzees write better code than that... :-) Maybe it was actually written by a cat walking across the keyboard?

              Speed of sound - 1100 ft/sec Speed of light - 186,000 mi/sec Speed of stupid - instantaneous.

              D 1 Reply Last reply
              0
              • L Lost User

                OriginalGriff wrote:

                written by three chimpanzees

                Chimpanzees write better code than that... :-) Maybe it was actually written by a cat walking across the keyboard?

                Speed of sound - 1100 ft/sec Speed of light - 186,000 mi/sec Speed of stupid - instantaneous.

                D Offline
                D Offline
                Daniel Pfeffer
                wrote on last edited by
                #7

                NotPolitcallyCorrect wrote:

                Chimpanzees write better code than that... :)

                They certainly do! Primate Programming(tm) Inc[^] :)

                If you have an important point to make, don't try to be subtle or clever. Use a pile driver. Hit the point once. Then come back and hit it again. Then hit it a third time - a tremendous whack. --Winston Churchill

                OriginalGriffO 1 Reply Last reply
                0
                • D Daniel Pfeffer

                  NotPolitcallyCorrect wrote:

                  Chimpanzees write better code than that... :)

                  They certainly do! Primate Programming(tm) Inc[^] :)

                  If you have an important point to make, don't try to be subtle or clever. Use a pile driver. Hit the point once. Then come back and hit it again. Then hit it a third time - a tremendous whack. --Winston Churchill

                  OriginalGriffO Offline
                  OriginalGriffO Offline
                  OriginalGriff
                  wrote on last edited by
                  #8

                  Obligatory Dilbert[^]

                  Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...

                  "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
                  "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

                  1 Reply Last reply
                  0
                  • P Pavlex4

                    How to convert this pascal code in C# :

                    uses crt;
                    var najbl:int64;
                    u,pok,zad,a:longint;
                    l:integer;
                    niz:array[1..946686] of int64;
                    uzet:array[1..6] of boolean;
                    w:string;
                    lpl:boolean;
                    function abs(x:int64):int64;
                    begin
                    if x>0 then abs:=x
                    else abs:=-x;
                    end;
                    function num2str(y:integer):string;
                    begin
                    num2str:='';
                    repeat
                    num2str:=chr(y mod 10+48)+num2str;
                    y:=y div 10
                    until y=0;
                    end;
                    procedure inc_uzet;
                    var ss:byte;
                    begin
                    for ss:=1 to 6 do
                    uzet[ss]:=false;
                    end;
                    procedure oznaci_po_redu(s:integer);
                    begin
                    l:=0;
                    while (s>0) do
                    begin
                    inc(l);
                    if not(uzet[l]) then dec(s);
                    end;
                    uzet[l]:=true;
                    end;
                    procedure dekodiraj(i:longint);
                    begin
                    if i<7 then uzet[i]:=true
                    else if i<127 then begin
                    dekodiraj((i-7) div 4 div 5 + 1);
                    oznaci_po_redu((i-7) div 4 - (i-7) div 4 div 5 * 5 + 1);
                    end
                    else if i<2047 then begin
                    dekodiraj((i-127) div 4 div 4 + 7);
                    oznaci_po_redu((i-127) div 4 - (i-127) div 4 div 4 * 4 + 1);
                    end
                    else if i<25087 then begin
                    dekodiraj((i-2047) div 4 div 3 + 127);
                    oznaci_po_redu((i-2047) div 4 - (i-2047) div 4 div 3 * 3 + 1);
                    end
                    else if i<209407 then begin
                    dekodiraj((i-25087) div 4 div 2 + 2047);
                    oznaci_po_redu((i-25087) div 4 - (i-25087) div 4 div 2 * 2 + 1);
                    end
                    else begin
                    dekodiraj((i-209407)div 4 + 25087);
                    oznaci_po_redu(1);
                    end;
                    end;
                    procedure dekodiraj1(i:longint);
                    var a:longint;
                    begin
                    if i<7 then begin
                    uzet[i]:=true;
                    w:=w+num2str(niz[i]);
                    lpl:=false;
                    end
                    else begin
                    if i<127 then begin
                    a:=(i-7) div 4 div 5 + 1;
                    dekodiraj1(a);
                    oznaci_po_redu((i-7) div 4 - 5*(a-1)+1);
                    end
                    else if i<2047 then begin
                    a:=(i-127) div 4 div 4 + 7;
                    dekodiraj1(a);
                    oznaci_po_redu((i-127) div 4 - 4*(a-7)+1);

                    L Offline
                    L Offline
                    Lost User
                    wrote on last edited by
                    #9

                    Unlocking a phone?

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups