bitwise increment one liner

M

Mantorok Redgormor

The only adder I was able to come up with for incrementing
by one, uses a for loop.

I was trying to do this without using a for loop
while emulating i++(it's for obfuscated code)

Anyone know of a way to increment by one continuously,
while updating the same value stored in an object,
without the need of such a loop? basically a one-liner.
 
K

Kevin Goodsell

Mantorok said:
The only adder I was able to come up with for incrementing
by one, uses a for loop.

I was trying to do this without using a for loop
while emulating i++(it's for obfuscated code)

Anyone know of a way to increment by one continuously,
while updating the same value stored in an object,
without the need of such a loop? basically a one-liner.

I don't understand your question at all. You may need to clarify in
order to receive help.

-Kevin
 
M

Mantorok Redgormor

Kevin Goodsell said:
I don't understand your question at all. You may need to clarify in
order to receive help.

-Kevin

Sorry, I'll re-explain.

I have a bitwise adder, that is, addition done with bitwise operators
to continuously add one while in a for loop
However, the adder itself is made up of a for loop.

So I have something like:

for(initialization; condition; for(my adder))

That inner for loop there just continues to add one
so currently it is an obfuscated way of doing the following:
++i;

I was wondering if anyone knew a way to emulate
++i;
Without the need of a loop, where it can be done by just a one liner?
Or possibly two/three liner minus the need for a loop
 
K

Kevin Goodsell

Mantorok said:
Sorry, I'll re-explain.

I have a bitwise adder, that is, addition done with bitwise operators
to continuously add one while in a for loop
However, the adder itself is made up of a for loop.

So I have something like:

for(initialization; condition; for(my adder))

That inner for loop there just continues to add one
so currently it is an obfuscated way of doing the following:
++i;

I was wondering if anyone knew a way to emulate
++i;
Without the need of a loop, where it can be done by just a one liner?
Or possibly two/three liner minus the need for a loop

So you are seeking a short (loop-free), but obfuscated method of
incrementing a variable?

-Kevin
 
B

Ben Pfaff

I was wondering if anyone knew a way to emulate
++i;
Without the need of a loop, where it can be done by just a one liner?
Or possibly two/three liner minus the need for a loop

Perhaps
i ^= (i & ~-~i) | (~i & -~i);
Works for me for small "unsigned" i, at least. For greatest
obscurity, it could be written as
i^=i&~-~i|~i&-~i;
This is decipherable in a few minutes with _Hacker's Delight_ by
Henry Warren, which I used to construct it, but probably baffling
otherwise.
 
M

Mantorok Redgormor

Ben Pfaff said:
Perhaps
i ^= (i & ~-~i) | (~i & -~i);
Works for me for small "unsigned" i, at least. For greatest
obscurity, it could be written as
i^=i&~-~i|~i&-~i;
This is decipherable in a few minutes with _Hacker's Delight_ by
Henry Warren, which I used to construct it, but probably baffling
otherwise.

is the latter portable across sign-magnitude, ones' complement,
and two's complement?

also thanks for the reference to that book, I checked it out on
amazon going to buy it.
 
B

Ben Pfaff

is the latter portable across sign-magnitude, ones' complement,
and two's complement?

Unsigned values don't have any of those forms. If you want to
use it for signed values, I suspect it will work on typical two's
complement systems, but not on sign-magnitude or ones' complement
systems.
 
J

James Dow Allen

The only adder I was able to come up with for incrementing
by one, uses a for loop.

I was trying to do this without using a for loop
while emulating i++(it's for obfuscated code)

If you're just trying to count, say, 99 times, you don't need
to count 0,1,2,3,4,... but can use any sequence with a sufficiently
long period. In that case, an "increment" like
i += i | i < 0
should work, with an appropriate starting value for i.
(This particular example produces non-portable code.)
That should improve obfuscation!

Such an obfuscated counter can be implemented with fewer transistors
than an ordinary counter. I dimly recall finding such a counter in
early MacIntosh while disassembling some of its floppy-disk access code.

James
 
P

Peter Shaggy Haywood

Groovy hepcat Mantorok Redgormor was jivin' on 17 Dec 2003 07:52:21
-0800 in comp.lang.c.
bitwise increment one liner's a cool scene! Dig it!
The only adder I was able to come up with for incrementing

You came up with a venomous reptile?
by one, uses a for loop.

I was trying to do this without using a for loop
while emulating i++(it's for obfuscated code)

Anyone know of a way to increment by one continuously,
while updating the same value stored in an object,
without the need of such a loop? basically a one-liner.

Well, since it's for obfuscated code... The following adds 19 to x.

int x=23,skedoo;
x:skedoo=0;if(x++,19>skedoo++)goto x;

Note the extra obfuscation achieved by using the same identifier for
both the label and the object being incremented as well as the use of
the comma operator.

--

Dig the even newer still, yet more improved, sig!

http://alphalink.com.au/~phaywood/
"Ain't I'm a dog?" - Ronny Self, Ain't I'm a Dog, written by G. Sherry & W. Walker.
I know it's not "technically correct" English; but since when was rock & roll "technically correct"?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,756
Messages
2,569,533
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top