Don't forget to read the rules of the forum. No current release restrictions. | Help Search Members Calendar

Logged in as: The Dreamslayer ( Log Out ) | My Controls · 0 New Messages · View New Posts · My Assistant

Mugen DEV Forum -> Development and Help Forums -> Development Discussion

bitwise operation
Track this topic | Email this topic | Print this topic

Enkephalin | Posted: Nov 13 2003, 09:05 AM
Member Group: Members Posts: 37 Member No.: 4215 Joined: 10-November 03
The expressions doc gives bitwise evaluators, but doesn't show how to set bits. Is this supported in Mugen yet?

SMI | Posted: Nov 13 2003, 10:19 AM
Member Group: Members Posts: 62 Member No.: 111 Joined: 14-September 02
I know two ways to accomplish such a thing:
First:
[State WhatEver, I don't Care]
Type = VarSet
trigger1 = Some Trigger Here!
var(0) = var(0) | floor(exp(var(1)*ln(2)) + 0.5)
Where var(0) is the var you want to set the bit, var(1) is the bit you want to set (may not be bigger than 31 nor smaller tha 0)
The other way is more straight:
[State WhatEver, I don't Care]
Type = VarSet
trigger1 = Some Trigger Here!
var(0) = var(0) | (The result of Power(2, Bit Value (0..31), such as 32, 256 and so on)
The first one is more generic. The second method allows you to set a fixed bit.
You may want to add a & mask to reset var(0) or make trick combination of the opperators to get nice results such a XOR.
Have fun, and always keep in mind this: exp(power * ln(base)) > base ** power.
This post has been edited by SMI on Nov 13 2003, 10:30 AM
--------------------
[murray voice]
I'm a powerful demonic force!
I'm the harbinger of your doom!
And the forces of darkness will applaud me as I stride through the gates of hell carrying your head on a pike!
[/murray voice]

Enkephalin | Posted: Nov 13 2003, 01:40 PM
Member Group: Members Posts: 37 Member No.: 4215 Joined: 10-November 03
Didn't realize it was so involved, but that's highly nifty to know. That's gonna
go in my toolbox.
Is there some benefit to using a generic bit? Is there anything you can do with
it that you can't do with an int?
Btw, bitwise XOR is already an operator in the expressions doc.

Renzo | Posted: Nov 13 2003, 03:18 PM
Street Fighter III 3rd Strike addict Group: Members Posts: 179 Member No.: 4184 Joined: 19-October 03
SMI, and 2**x wonīt work?
where x is the (x+1)th bit you want to set.
I havenīt tested it yet, but it makes sense and itīs equal to the formula you gave.
--------------------
renzo.studiosmh.com
Thank you Mario, but the princess is in another castle.

SMI | Posted: Nov 13 2003, 05:18 PM
Member Group: Members Posts: 62 Member No.: 111 Joined: 14-September 02
Renzo: I don't trust the ** operator. The solution I provided gives more accurate results.
Enkephalin:
The results are the same, but the generic solution makes it easier to debug and maintain the code.
This post has been edited by SMI on Nov 13 2003, 05:19 PM
--------------------
[murray voice]
I'm a powerful demonic force!
I'm the harbinger of your doom!
And the forces of darkness will applaud me as I stride through the gates of hell carrying your head on a pike!
[/murray voice]

Maximilian Jenus | Posted: Nov 23 2003, 04:51 AM
[E] Group: Members Posts: 243 Member No.: 215 Joined: 15-September 02
I do not get the question... the advantage of using bitwise operators is that they allow for further tweaks and better code performance by using optimization of simple repetitive conditions. Another advantage is data compression in case you find 60 int vars too few of a number for your needs.
--------------------
It is your selection of relevant facts that will create interest.A sweeping conception carries with vitality ,purpose and conviction. The more detailed and involved we get,the less forceful and powerful is our message.We can take a compass and draw a circle perfectly ,but we have left no trace of ou

Enkephalin | Posted: Nov 24 2003, 06:56 PM
Member Group: Members Posts: 37 Member No.: 4215 Joined: 10-November 03
I meant was there advantage to setting a generic bit as opposed to a fixed bit. I was thinking I could cram a whole bunch of attributes into one bitmap.

Maximilian Jenus | Posted: Nov 25 2003, 04:38 AM
[E] Group: Members Posts: 243 Member No.: 215 Joined: 15-September 02
the advantage is the usual coding dilema, performance against clarity of code; but since they are constants and ebyte might some day implement code optimization in their parser i suggest you to use the generic bit approach.
--------------------
It is your selection of relevant facts that will create interest.A sweeping conception carries with vitality ,purpose and conviction. The more detailed and involved we get,the less forceful and powerful is our message.We can take a compass and draw a circle perfectly ,but we have left no trace of ou

« Next Oldest | Development Discussion | Next Newest »

Close Topic Options
Track this topic
Receive email notification when a reply has been made to this topic and you are not active on the board.
Subscribe to this forum
Receive email notification when a new topic is posted in this forum and you are not active on the board.
Download / Print this Topic
Download this topic in different formats or view a printer friendly version.
- M.U.G.E.N Development Forum - Contact an admin - ELECBYTE - Shin Mugen -
Powered by Invision Power Board(U) v1.2 © 2003 IPS, Inc.