472,353 Members | 1,057 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,353 software developers and data experts.

bitwise increment one liner

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
Nov 14 '05 #1
8 6219
Mantorok Redgormor wrote:
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
--
My email address is valid, but changes periodically.
To contact me please use the address from a recent posting.
Nov 14 '05 #2
Kevin Goodsell <us*********************@neverbox.com> wrote in message news:<L3***************@newsread2.news.pas.earthli nk.net>...
Mantorok Redgormor wrote:
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


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
Nov 14 '05 #3
Mantorok Redgormor wrote:

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
--
My email address is valid, but changes periodically.
To contact me please use the address from a recent posting.
Nov 14 '05 #4
ne*****@tokyo.com (Mantorok Redgormor) writes:
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.
--
"Some people *are* arrogant, and others read the FAQ."
--Chris Dollin
Nov 14 '05 #5
Ben Pfaff <bl*@cs.stanford.edu> wrote in message news:<87************@pfaff.stanford.edu>...
ne*****@tokyo.com (Mantorok Redgormor) writes:
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.


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
Nov 14 '05 #6
ne*****@tokyo.com (Mantorok Redgormor) writes:
Ben Pfaff <bl*@cs.stanford.edu> wrote in message news:<87************@pfaff.stanford.edu>...
ne*****@tokyo.com (Mantorok Redgormor) writes:
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.


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.
--
"What is appropriate for the master is not appropriate for the novice.
You must understand the Tao before transcending structure."
--The Tao of Programming
Nov 14 '05 #7
ne*****@tokyo.com (Mantorok Redgormor) wrote in message news:<41**************************@posting.google. com>...
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
Nov 14 '05 #8
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"?
Nov 14 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: D. Alvarado | last post by:
Hello, Does anyone have a PHP 4 one-liner (or two-liner) for extracing a file from a directory in which I know the word "footer" is guaranteed to...
0
by: Xah Lee | last post by:
One-Liner Loop in Functional Style Xah Lee, 200510 Today we show a example of a loop done as a one-liner of Functional Programing style. ...
6
by: jas_lx | last post by:
The basic understanding of what bitwise operators (& ^ | >> << ) comes fairly simple, as long as one has a fundamental understanding of bits,...
7
by: Jerry | last post by:
I want an algorithm that do arithmetic operations(divide,mutiply,add etc.)just using bitwise operators:<<,>>,&,|,^; For example,how "a/10"...
2
by: Steve Summit | last post by:
-----BEGIN PGP SIGNED MESSAGE----- It's often explained that the reason for some of the imprecision in C's definition is so that C can be...
9
by: Christopher Weaver | last post by:
I know that the bitwise AND of 8 and 4 will return 0 or false and the bitwise AND of 8 and 9 will return 1 or true but I don't know how to write...
5
by: noridotjabi | last post by:
I'm learning to program in C and any tutorial or book that I read likes to briefly touch on birdies operators and then move on without giving any...
5
by: Gigs_ | last post by:
Can someone explain me bitwise expression? few examples for every expression will be nice x << y Left shift x >y Right shift x & y Bitwise AND...
3
by: srinivasan srinivas | last post by:
Hi, Do we have python one-liner like perl one-liner 'perl -e'?? Thanks, Srini Unlimited freedom, unlimited storage. Get it now,...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.