Results 1 to 14 of 14

Thread: Bitwise

  1. #1
    Join Date
    Jan 2008
    Location
    Ontario, Canada
    Posts
    7,805
    Mentioned
    5 Post(s)
    Quoted
    3 Post(s)

    Default Bitwise

    SCAR Code:
    program New;

    procedure DropAllExcept(DontDrop: TIntegerArray);
    var
      inv: byte;
      i, h: Integer;
    begin
      //inv := 1 shl 28;
      //Writeln(IntToStr(inv));
      h := high(DontDrop);
      for i := 0 to h do
        inv := inv or (1 shl DontDrop[i]);
      for i := 1 to 28 do
        if (((inv shr i) and 1) <> 0) then
          Writeln('not Dropping number ' + IntToStr(i));
    end;

    var
      val: byte;
    begin
      DropAllExcept([25, 22, 7, 8, 9, 23]);
    end.

    Why won't it recognize numbers > 7?

    Thanks boys 'n' girls!

    ~n2
    Writing an SRL Member Application | [Updated] Pascal Scripting Statements
    My GitHub

    Progress Report:
    13:46 <@BenLand100> <SourceCode> @BenLand100: what you have just said shows you 
                        have serious physchological problems
    13:46 <@BenLand100> HE GETS IT!
    13:46 <@BenLand100> HE FINALLY GETS IT!!!!1

  2. #2
    Join Date
    Oct 2006
    Location
    ithurtsithurtsithurtsithurts
    Posts
    2,930
    Mentioned
    7 Post(s)
    Quoted
    135 Post(s)

    Default

    Not entirely sure, but if you switch inv from byte to Integer, it works properly.

  3. #3
    Join Date
    May 2006
    Location
    Amsterdam
    Posts
    3,620
    Mentioned
    5 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by Nava2 View Post
    SCAR Code:
    program New;

    procedure DropAllExcept(DontDrop: TIntegerArray);
    var
      inv: byte;
      i, h: Integer;
    begin
      //inv := 1 shl 28;
      //Writeln(IntToStr(inv));
      h := high(DontDrop);
      for i := 0 to h do
        inv := inv or (1 shl DontDrop[i]);
      for i := 1 to 28 do
        if (((inv shr i) and 1) <> 0) then
          Writeln('not Dropping number ' + IntToStr(i));
    end;

    var
      val: byte;
    begin
      DropAllExcept([25, 22, 7, 8, 9, 23]);
    end.

    Why won't it recognize numbers > 7?

    Thanks boys 'n' girls!

    ~n2
    Byte = 8 bits -> 0..7
    LongWord = 4 Bytes = 32 bits -> 0..31
    Verrekte Koekwous

  4. #4
    Join Date
    Jan 2007
    Posts
    8,876
    Mentioned
    123 Post(s)
    Quoted
    327 Post(s)

    Default

    Quote Originally Posted by mastaraymond View Post
    Byte = 8 bits -> 0..7
    LongWord = 4 Bytes = 32 bits -> 0..31
    nava2...
    But why do you want to make it bitwise anyways? not everybody understands shiftleft and shiftright..

  5. #5
    Join Date
    May 2006
    Location
    Amsterdam
    Posts
    3,620
    Mentioned
    5 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by Zyt3x View Post
    nava2...
    But why do you want to make it bitwise anyways? not everybody understands shiftleft and shiftright..
    Well with bitwise we could just make it something like

    DropAllExcept(inv_1 or inv_6 or inv_16);

    Where inv_x are consts.
    Verrekte Koekwous

  6. #6
    Join Date
    Jan 2008
    Location
    Ontario, Canada
    Posts
    7,805
    Mentioned
    5 Post(s)
    Quoted
    3 Post(s)

    Default

    Fail on my behalf.. thanks.

    SCAR Code:
    program New;

    procedure DropAllExceptNew(DontDrop: TIntegerArray);
    var
      inv, i, h: Integer;
    begin
      //inv := 1 shl 28;
      //Writeln(IntToStr(inv));
      h := high(DontDrop);
      for i := 0 to h do
        { Set the bit associated with the DontDrop Array }
        inv := inv or (1 shl DontDrop[i]);
      for i := 1 to 28 do
        { Check the bit at i, and if its high, then we dont drop. }
        if (((inv shr i) and 1) = 0) then
        begin end;//  Writeln('not Dropping number ' + IntToStr(i));
    end;

    {*******************************************************************************
    procedure DropAllExcept(IgnoreInvSlots: TIntegerArray);
    By: R1ch
    Description: Drops everything in inventory. Ignores slots specified by
    IgnoreInvSlots array.
    *******************************************************************************}

    procedure DropAllExceptOld(IgnoreInvSlots: TIntegerArray);
    var
      I: Byte;
    begin
      for I := 1 to 28 do
        if (not InIntArray(IgnoreInvSlots, I)) then
        begin end;//  Writeln('Dropping number ' + IntToStr(i));
    end;

    var
      i, t: Integer;
    begin
      t := GetSystemTime;
      for i := 0 to 9999 do
        DropAllExceptNew([25, 22, 7, 8, 9, 23]);
      t := GetSystemTime - t;
      Writeln('New took: ' + FloatToStr(t / 10000) + 'ms per, total: ' + intToStr(t) + 'ms');
      t := GetSystemTime;
      for i := 0 to 9999 do
        DropAllExceptOld([25, 22, 7, 8, 9, 23]);
      t := GetSystemTime - t;
      Writeln('Old took: ' + FloatToStr(t / 10000) + 'ms per, total: ' + intToStr(t) + 'ms');
    end.

    Code:
    Successfully compiled (41 ms)
    New took: 0.1327ms per, total: 1327ms
    Old took: 0.1727ms per, total: 1727ms
    Successfully executed
    Would be more significant with more in the array.
    Last edited by Nava2; 12-06-2009 at 04:26 PM.
    Writing an SRL Member Application | [Updated] Pascal Scripting Statements
    My GitHub

    Progress Report:
    13:46 <@BenLand100> <SourceCode> @BenLand100: what you have just said shows you 
                        have serious physchological problems
    13:46 <@BenLand100> HE GETS IT!
    13:46 <@BenLand100> HE FINALLY GETS IT!!!!1

  7. #7
    Join Date
    May 2007
    Location
    knoxville
    Posts
    2,873
    Mentioned
    7 Post(s)
    Quoted
    70 Post(s)

    Default

    SCAR Code:
    procedure dropallexept(i: TIntegerarray);
    var
      a, b : integer;
    begin
      for a:= 1 to 28 do
        for b := 0 to high(i) do
          if not i[b + 1] = a then dropitem(a);
    end;

    wouldnt that work?

    dropitem([inv_1, inv_7, inv_27]);
    <TViYH> i had a dream about you again awkwardsaw
    Malachi 2:3

  8. #8
    Join Date
    May 2006
    Location
    Amsterdam
    Posts
    3,620
    Mentioned
    5 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by Awkwardsaw View Post
    SCAR Code:
    procedure dropallexept(i: TIntegerarray);
    var
      a, b : integer;
    begin
      for a:= 1 to 28 do
        for b := 0 to high(i) do
          if not i[b + 1] = a then dropitem(a);
    end;

    wouldnt that work?

    dropitem([inv_1, inv_7, inv_27]);
    That's invalid code for sure -> Can return out of range..
    And no, your setup wouldn't work. It would drop the Item "a" multiple times..
    Verrekte Koekwous

  9. #9
    Join Date
    May 2007
    Location
    knoxville
    Posts
    2,873
    Mentioned
    7 Post(s)
    Quoted
    70 Post(s)

    Default

    Quote Originally Posted by mastaraymond View Post
    That's invalid code for sure -> Can return out of range..
    And no, your setup wouldn't work. It would drop the Item "a" multiple times..
    not the actual code, the idea.
    <TViYH> i had a dream about you again awkwardsaw
    Malachi 2:3

  10. #10
    Join Date
    May 2006
    Location
    Amsterdam
    Posts
    3,620
    Mentioned
    5 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by Awkwardsaw View Post
    not the actual code, the idea.
    Would become something like
    SCAR Code:
    procedure dropallexept(i: TIntegerarray);
    var
      a, b : integer;
      bool : boolean;
    begin
      for a:= 1 to 28 do
      begin
        bool := false;
        for b := 0 to high(i) do
          if i[b] = a then
          begin;
            bool := true;
            break;
          end;
        if not bool then
          DropItem(a);
      end;
    end;
    Verrekte Koekwous

  11. #11
    Join Date
    Feb 2006
    Location
    Amsterdam
    Posts
    13,692
    Mentioned
    146 Post(s)
    Quoted
    130 Post(s)

    Default

    Please don't put this in SRL.
    Even if it faster, it is pretty stupid to do so. It's not like the algorithm in DropAllExcept is going to make any difference.



    The best way to contact me is by email, which you can find on my website: http://wizzup.org
    I also get email notifications of private messages, though.

    Simba (on Twitter | Group on Villavu | Website | Stable/Unstable releases
    Documentation | Source | Simba Bug Tracker on Github and Villavu )


    My (Blog | Website)

  12. #12
    Join Date
    Jan 2008
    Location
    Ontario, Canada
    Posts
    7,805
    Mentioned
    5 Post(s)
    Quoted
    3 Post(s)

    Default

    Quote Originally Posted by Wizzup? View Post
    Please don't put this in SRL.
    Even if it faster, it is pretty stupid to do so. It's not like the algorithm in DropAllExcept is going to make any difference.
    Sawy.
    Writing an SRL Member Application | [Updated] Pascal Scripting Statements
    My GitHub

    Progress Report:
    13:46 <@BenLand100> <SourceCode> @BenLand100: what you have just said shows you 
                        have serious physchological problems
    13:46 <@BenLand100> HE GETS IT!
    13:46 <@BenLand100> HE FINALLY GETS IT!!!!1

  13. #13
    Join Date
    Feb 2006
    Location
    Amsterdam
    Posts
    13,692
    Mentioned
    146 Post(s)
    Quoted
    130 Post(s)

    Default

    Quote Originally Posted by Nava2 View Post
    Sawy.
    It's good to learn bitwise and all, but it's not very well suited for SRL.



    The best way to contact me is by email, which you can find on my website: http://wizzup.org
    I also get email notifications of private messages, though.

    Simba (on Twitter | Group on Villavu | Website | Stable/Unstable releases
    Documentation | Source | Simba Bug Tracker on Github and Villavu )


    My (Blog | Website)

  14. #14
    Join Date
    Jan 2008
    Location
    Ontario, Canada
    Posts
    7,805
    Mentioned
    5 Post(s)
    Quoted
    3 Post(s)

    Default

    Quote Originally Posted by Wizzup? View Post
    It's good to learn bitwise and all, but it's not very well suited for SRL.
    Why is it not, it is appropriately commented.. meaning its faster, understandable to those who want to.. Whats the downside?
    Writing an SRL Member Application | [Updated] Pascal Scripting Statements
    My GitHub

    Progress Report:
    13:46 <@BenLand100> <SourceCode> @BenLand100: what you have just said shows you 
                        have serious physchological problems
    13:46 <@BenLand100> HE GETS IT!
    13:46 <@BenLand100> HE FINALLY GETS IT!!!!1

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •