[PLUGIN] Bitwise Operations

This forum is currently in read-only mode.
0 favourites
From the Asset Store
The I18N (Translation) is a Construct plugin created to translate text in game.
  • Hi guys, just learnt how to play with c++ and how to make plugins

    Some little operator that CC didn't have yet.

    Well... I warn you, it might be difficult to find a good practical use for these but heh... Better too much tools than not enough

    Here is the plugin

    Bit.zip

    And a Demo cap to see what it's about

    bitDemo.cap

    This object as one condition and 11 expressions

    Conditions :

    • "Is bit set to One" check if a given bit in the bit field is set to 1, you can invert it to check for 0

    Expression :

    • AND :

        1 AND 1 = 1

        1 AND 0 = 0

        0 AND 1 = 0

        0 AND 0 = 0

    • OR

        1 OR 1 = 1

        1 OR 0 = 1

        0 OR 1 = 1

        0 OR 0 = 0

    • XOR (eXclusisve OR)

        1 XOR 1 = 0

        1 XOR 0 = 1

        0 XOR 1 = 1

        0 XOR 0 = 0

    • NOT

        NOT 1 = 0

        NOT 0 = 1

    • LEFT SHIFT

        45(101101) << 2 = 180(10110100)

    • RIGHT SHIFT

        45(101101) >> 2 = 11(1011)

    • set to 1

        you can set any bit of a given bitfield to 1

    • set to 0

        you can set any bit of a given bitfield to 0

    • toggle

        you can toggle any bit of a given bitfield

    • decimal to binary

        convert decimal number to binary number (works only with positive number)

    • binary to decimal

        convert binary number to decimal number (works only with positive number)

    Have fun with it, and if you find some ways to use it, please tell me (:Yann2011-11-06 00:30:17

  • Thanks this is a useful plugin :D

    I could not run the example for some reason however so i made a new project and tested the bin <> dec value converting and found a error (i think).

    I noticed if you convert to binary values from decimal you can use high numbers. If you are converting from binary to decimal however it only allows up to 1023 and 1024 returns a -1 value as i guess it cannot go higher than that. So if it's possible it would be great if binary to decimal could allow for higher numbers.

  • Binary to decimal :

    example : 10110100 -> 180

    Well, binary to decimal if you don't put a binary number, that is to say, a number with only 1 and 0, it returns -1 (my way to say it's undefined)

    Decimal to Binary :

    example : 5670 -> "1011000100110"

    The weird thing is that you should be able to convert pretty high number

    from decimal to binary. As c++ tends to write high number with scientific notation (e.g. 1.54054006e082) I output the binary form in a string. So the only limitation to display it is the size of the text object you use.

    in each case, the function should return -1 if you put negative numbers or for the binary to decimal if you put a non binary number.

  • What i am saying is it cannot handle the binary equal to a value of 1024. Here is a example:

    Decimal to Binary :

    example : 1024 -> 10000000000

    Binary to decimal :

    example : 10000000000 -> -1

    If you are converting from a decimal it seems fine and allows high numbers as you say but doing the same from binary does not seem to work.

  • ok I can reproduce your bug, I'll see about that

  • Thanks :)

  • Oh yeah sorry :D I saw and that's an issue with construct. Something with size of int and stuff like that. I don't think I can do anything about that. But you know... These functions aren't that inportant (it was more for easy debug), the better is to be able to do all the bitwise operation (:

  • Bitwise operations! Finally Construct Classic grows up. Can't tell how often I wished for it to be present.

    Thank you :)

    p.s. now just add support for hex and I'm happy for months ;)

  • hex?... if you write what ACE you want I could see what I can do but not before the 23th 'cause I'm working on the c2 contest til then (:

  • I'd love to have my own data constructions to store them somewhere (e.g. to a hash table)

    Something like id, x, y, animation frame could be a simple string like "A19EB408"

    ACEs:

    hex2decimal

    returns the decimal expression of the hex-value

    decimal2hex

    returns the hexadecimal expression of the number

    sethex (hex, number, byte position, byte length)

    changes hex by converting number and change the specified part of hex ("A31C012B", 255, 3, 1 -> "A31CFF2B")

    gethex (hex, byte position, byte length)

    returns the decimal expression of the specified part of hex ("A31C012B", 2, 2 -> 7169)

    Good luck for the contest :)

  • ok, I just hope that I can easily go back and forth between string and hexadecimal int in c++ 'cause I might not look like it but I'm still a c++ n00b

    For instance dec2bin and bin2dec functions of the current plugin aren't really good/usefull because of int limitations.

    'Cause after all, bitwise operations are made on decimal int.

    So you will probably set things in decimal and the hexadecimal calculation will probably just be under the hood. Like with bitwise stuff.

    Hmmm... maybe an hex2dec function to be able to set things in hexadecimal format with a string... hmmm... If I can easily typecast string to hex int as I said...

    I'm thinking while typing...

    Remind me at the end of the month I might get carried away in other projects (:

  • With C++ you have limits on the data type values you can use:

    signed: -2147483648 to 2147483647

    unsigned: 0 to 4294967295

    etc, maybe use a long int for the Binary to decimal problem or maybe use doubles then round to int again etc.

    Using a string input as a workaround then converting data types could also work.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • well, it's a pain and I don't have that much room for conversion 'cause the param you enter in cc when you use the plugin are input in the plugin via either simple int or string (as far as I know param[0].GetInt() or param[0].GetString() are the function used to retrieve the param). I'm not knowledgeable enough to know if I can create my own GetLongInt() function to handle that.

    And anyway, dec2bin and bin2dec really are just for checking how bitwise operation works, you really don't need that in the code itself.

    you will do a 8 and 4 (knowing that "binarily" it is 1000 and 100) If you do a bin2dec(1000) and bin2dec(100) instead, you lose all the speed and efficiency of bitwise operation.

  • I just wanted to say thanks for this. I'd been searching the manual for this kind of functionality, only to find that it isn't implemented in Construct. Good thing we can extend its functionality with plugins.

  • Elyzius you're welcome (:

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)