The Artima Developer Community
Sponsored Link

Java Buzz Forum
How to find If Number Power of Two Using Bitwise Operator

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Javin Paul

Posts: 1090
Nickname: javinpaul
Registered: Jan, 2012

Javin Paul is Java Programmer working on Finance domain.
How to find If Number Power of Two Using Bitwise Operator Posted: Jun 5, 2015 8:58 AM
Reply to this message Reply

This post originated from an RSS feed registered with Java Buzz by Javin Paul.
Original Post: How to find If Number Power of Two Using Bitwise Operator
Feed Title: Java67
Feed URL: http://www.java67.com/feeds/posts/default?alt=rss
Feed Description: Java and technology tutorials, tips, questions for all programmers.
Latest Java Buzz Posts
Latest Java Buzz Posts by Javin Paul
Latest Posts From Java67

Advertisement
In this Java Programming tutorial you will learn how to check if number is Power of two using bitwise operator. Main purpose or this program is to teach you how to use bit-wise operators like  bitwise AND (&)  in Java. A number is said to be power of two if all its prime factors are 2, but in binary world things works little differently. If you have read hacker's delight book then you know that there are several technique to check if a number is power of two or not, one of them is performing bit-wise AND operation between number and number -1, if result is zero then number is power of two. Just remember, here we are doing binary subtraction and not decimal one. In bitwise operator, each bit is used in evaluation for example if you use bitwise AND then each bit of both operand will go through AND operation and result will contain 1 only if both bits are one otherwise zero. I will explain how exactly this program work, but let's first see the program itself.
Read more »

Read: How to find If Number Power of Two Using Bitwise Operator

Topic: Why does it matter that Future is a monad? Previous Topic   Next Topic Topic: Neo4j: The BBC Champions League graph

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use