background preloader

Bit Twiddling Hacks

Bit Twiddling Hacks
By Sean Eron Anderson seander@cs.stanford.edu Individually, the code snippets here are in the public domain (unless otherwise noted) — feel free to use them however you please. The aggregate collection and descriptions are © 1997-2005 Sean Eron Anderson. The code and descriptions are distributed in the hope that they will be useful, but WITHOUT ANY WARRANTY and without even the implied warranty of merchantability or fitness for a particular purpose. As of May 5, 2005, all the code has been tested thoroughly. Thousands of people have read it. Contents About the operation counting methodology When totaling the number of operations for algorithms here, any C operator is counted as one operation. Compute the sign of an integer The last expression above evaluates to sign = v >> 31 for 32-bit integers. Alternatively, if you prefer the result be either -1 or +1, then use: sign = +1 | (v >> (sizeof(int) * CHAR_BIT - 1)); // if v < 0 then -1, else +1 sign = (v ! Patented variation: f = v && ! Sean A.

http://graphics.stanford.edu/~seander/bithacks.html

Related:  programming

untitled Author Spotlight About Intel® 64 and IA-32 Architectures Software Developer Manuals These manuals describe the architecture and programming environment of the Intel® 64 and IA-32 processors. Links Faster than C ― Andreas Zwinkau Judging the performance of programming languages, usually C is called the leader, though Fortran is often faster. New programming languages commonly use C as their reference and they are really proud to be only so much slower than C. Few language designer try to beat C. What does it take for a language to be faster than C? untitled These manuals describe the architecture and programming environment of the Intel® 64 and IA-32 architectures. Combined Volume Set of Intel® 64 and IA-32 Architectures Software Developer’s ManualsFour-Volume Set of Intel® 64 and IA-32 Architectures Software Developer’s ManualsTen-Volume Set of Intel® 64 and IA-32 Architectures Software Developer's ManualsIntel® architecture instruction set extensions programming referenceSoftware Optimization Reference ManualUncore Performance Monitoring Reference ManualsRelated Specifications, Application Notes, and White Papers Electronic versions of these documents allow you to quickly get to the information you need and print only the pages you want. The Intel® 64 and IA-32 architectures software developer's manuals are now available for download via one combined volume, a four volume set or a ten volume set. All content is identical in each set; see details below. At present, downloadable PDFs of all volumes are at version 071.

s Nginx Tutorials (version 2012.03.23) I've been doing a lot of work in the Nginx world over the last few years and I've also been thinking about writing series of tutorial-like articles to explain to more people what I've done and what I've learned in this area. Now I have finally decided to post serial tutorials to the Sina Blog in Chinese. Every article will have one rough topic and will be in a rather casual style. They're not parts of a book after all. But I do have plans to re-orginaize these stuffs to form a real book. Guide to x86 Assembly Contents: Registers | Memory and Addressing | Instructions | Calling Convention This guide describes the basics of 32-bit x86 assembly language programming, covering a small but useful subset of the available instructions and assembler directives. There are several different assembly languages for generating x86 machine code. The one we will use in CS216 is the Microsoft Macro Assembler (MASM) assembler. MASM uses the standard Intel syntax for writing x86 assembly code.

Deploying My Django Application to DotCloud This post is out of date. A revised tutorial can be found HERE. I have recently written about ep.io and gondor.io, two new Python/Django hosting services that are currently in beta. untitled See also my blog Contents Optimization manuals

Django Hosting Roundup: (Ep.io vs Gondor.io vs DotCloud vs Heroku vs AppHosted vs DjangoZoom) Who wins? Intro For the past 6 weeks I have been trying out all of the new django/python hosting services that are currently available today, and I have been writing about my experiences along the way. It only makes sense to conclude this series of articles with one last article comparing all of the services against each other. It is important to note that many of these services are still in development and aren't even available to the general public, so I'll try to keep this article up to date as these services change over time. With that said, don't take my word for it, go out and try all of these services on your own and find out which one you like the best, you won't be disappointed. Quick Recap

Library Documentation Accumulators Framework for incremental calculation, and collection of statistical accumulators. Author(s) Platform Overview Applications & Services On dotCloud, an application is a collection of one or more services working together. Each service is a component in your application, such as a front-end application server, a worker, or a database. Population count Population count You are encouraged to solve this task according to the task description, using any language you may know. The population count is the number of 1s (ones) in the binary representation of a non-negative integer. Population count is also known as pop count, popcount, sideways sum, and Hamming weight.

Related: