Interrupt Enable

Life is a series of rude awakenings

Sunday, November 30, 2008

isTwoPower

Very simple and elegant function to test if a number is a power of two.

int isTwoPower(int n){
if( n < 1 )
return 0;
return !(n & (n-1));
}
Posted by Daniel Băluță at 2:42 AM
Labels: algorithm, idea, tricks

1 comment:

Sinziana said...

super!
Bine ai venit in blogosfera :D

December 1, 2008 at 6:38 AM

Post a Comment

Newer Post Older Post Home
Subscribe to: Post Comments (Atom)

About Me

My photo
Daniel Băluță
romanian blood,oltenian heart.
View my complete profile

Blog roll

  • Linux Journal - The Original Magazine of the Linux Community
    Beyond APT: Software Management with Flatpak on Ubuntu
    2 days ago
  • Ubuntu Geek
    Clusterssh – Administer multiple ssh or rsh shells simultaneously
    4 years ago
  • Joel on Software
    Welcome, Prashanth!
    5 years ago
  • Linux Magazine
    Scripting, Part Two: Looping for Fun and Profit
    13 years ago
  • Rusty's Bleeding Edge Page
    Finally, Rusty's Blog Moves to WordPress
    15 years ago

Daniel Baluta's shared items

Blog Archive

  • ►  2011 (1)
    • ►  June (1)
  • ►  2009 (6)
    • ►  May (1)
    • ►  March (3)
    • ►  February (2)
  • ▼  2008 (5)
    • ►  December (3)
    • ▼  November (2)
      • isTwoPower
      • Hello World!
Simple theme. Theme images by gaffera. Powered by Blogger.