[PLUGIN] Bitwise Operations

Completed plugins, behaviors and effects.

Post » Sun Nov 06, 2011 12:28 am

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
Last edited by Yann on Sun Sep 14, 2014 11:35 pm, edited 1 time in total.
B
60
S
22
G
14
Posts: 1,479
Reputation: 16,346

Post » Mon Nov 07, 2011 4:45 pm

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.
B
9
S
3
G
4
Posts: 55
Reputation: 2,607

Post » Tue Nov 08, 2011 7:12 am

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.
B
60
S
22
G
14
Posts: 1,479
Reputation: 16,346

Post » Tue Nov 08, 2011 4:54 pm

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.FireLight2011-11-08 16:59:31
B
9
S
3
G
4
Posts: 55
Reputation: 2,607

Post » Tue Nov 08, 2011 5:41 pm

ok I can reproduce your bug, I'll see about thatYann2011-11-08 17:44:45
B
60
S
22
G
14
Posts: 1,479
Reputation: 16,346

Post » Mon Dec 05, 2011 11:07 am

Thanks :)
B
9
S
3
G
4
Posts: 55
Reputation: 2,607

Post » Mon Dec 05, 2011 11:40 am

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 (:Yann2011-12-05 11:40:42
B
60
S
22
G
14
Posts: 1,479
Reputation: 16,346

Post » Tue Dec 06, 2011 2:05 am

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 ;)
Image
B
23
S
8
G
10
Posts: 1,820
Reputation: 8,242

Post » Tue Dec 06, 2011 3:42 am

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 (:
B
60
S
22
G
14
Posts: 1,479
Reputation: 16,346

Post » Tue Dec 06, 2011 8:26 am

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 :)
Image
B
23
S
8
G
10
Posts: 1,820
Reputation: 8,242

Next

Return to Completed addons

Who is online

Users browsing this forum: No registered users and 0 guests