473,399 Members | 3,106 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 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 6301
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 be in the file name, I know the precise directory...
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. Suppose you have a list of file full paths of...
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, bytes and binary. Having done some Win32...
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" can be implemented. I just want a hint. Thanks.
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 implemented on different kinds of machines -- say, those...
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 the synax for it in C#. I have a value that ranges...
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 sort of example application of them. Call me what...
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 x | y Bitwise OR x ^ y Bitwise XOR (exclusive...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.