Connecting Tech Pros Worldwide Help | Site Map

bitwise increment one liner

Mantorok Redgormor
Guest
 
Posts: n/a
#1: Nov 14 '05
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.



--
nethlek
Kevin Goodsell
Guest
 
Posts: n/a
#2: Nov 14 '05

re: bitwise increment one liner


Mantorok Redgormor wrote:
[color=blue]
> 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.
>[/color]

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

-Kevin
--
My email address is valid, but changes periodically.
To contact me please use the address from a recent posting.
Mantorok Redgormor
Guest
 
Posts: n/a
#3: Nov 14 '05

re: bitwise increment one liner


Kevin Goodsell <usenet1.spamfree.fusion@neverbox.com> wrote in message news:<L33Eb.8678$0s2.81@newsread2.news.pas.earthli nk.net>...[color=blue]
> Mantorok Redgormor wrote:
>[color=green]
> > 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.
> >[/color]
>
> I don't understand your question at all. You may need to clarify in
> order to receive help.
>
> -Kevin[/color]

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




--
nethlek
Kevin Goodsell
Guest
 
Posts: n/a
#4: Nov 14 '05

re: bitwise increment one liner


Mantorok Redgormor wrote:
[color=blue]
>
> 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[/color]

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

-Kevin
--
My email address is valid, but changes periodically.
To contact me please use the address from a recent posting.
Ben Pfaff
Guest
 
Posts: n/a
#5: Nov 14 '05

re: bitwise increment one liner


nethlek@tokyo.com (Mantorok Redgormor) writes:
[color=blue]
> 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[/color]

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.
--
"Some people *are* arrogant, and others read the FAQ."
--Chris Dollin
Mantorok Redgormor
Guest
 
Posts: n/a
#6: Nov 14 '05

re: bitwise increment one liner


Ben Pfaff <blp@cs.stanford.edu> wrote in message news:<87n09q3694.fsf@pfaff.stanford.edu>...[color=blue]
> nethlek@tokyo.com (Mantorok Redgormor) writes:
>[color=green]
> > 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[/color]
>
> 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.[/color]

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.



--
nethlek
Ben Pfaff
Guest
 
Posts: n/a
#7: Nov 14 '05

re: bitwise increment one liner


nethlek@tokyo.com (Mantorok Redgormor) writes:
[color=blue]
> Ben Pfaff <blp@cs.stanford.edu> wrote in message news:<87n09q3694.fsf@pfaff.stanford.edu>...[color=green]
> > nethlek@tokyo.com (Mantorok Redgormor) writes:
> >[color=darkred]
> > > 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[/color]
> >
> > 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.[/color]
>
> is the latter portable across sign-magnitude, ones' complement,
> and two's complement?[/color]

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.
--
"What is appropriate for the master is not appropriate for the novice.
You must understand the Tao before transcending structure."
--The Tao of Programming
James Dow Allen
Guest
 
Posts: n/a
#8: Nov 14 '05

re: bitwise increment one liner


nethlek@tokyo.com (Mantorok Redgormor) wrote in message news:<41ec7ac0.0312170752.550faab1@posting.google. com>...[color=blue]
> 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)[/color]

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
Peter Shaggy Haywood
Guest
 
Posts: n/a
#9: Nov 14 '05

re: bitwise increment one liner


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!
[color=blue]
>The only adder I was able to come up with for incrementing[/color]

You came up with a venomous reptile?
[color=blue]
>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.[/color]

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"?
Closed Thread