The Artima Developer Community
Sponsored Link

Java Buzz Forum
Decimal to Binary Conversion in Java

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.
Decimal to Binary Conversion in Java Posted: Mar 14, 2014 11:08 PM
Reply to this message Reply

This post originated from an RSS feed registered with Java Buzz by Javin Paul.
Original Post: Decimal to Binary Conversion in Java
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
This week's programming exercise is to write a program to convert decimal number to binary in Java. It's a simple exercise for beginners who has just started learning Java programming language. Decimal numbers are base 10 numbers, which means their are exactly 10 digits to represent number, starting from 0 to 9, on the other hand binary number system has just two digits 0 and 1, which is known as bits. Binary numbers has lot of use in digital world, in fact binary is language of computers where 0 and 1 represent true/false, on/off and becomes key for logic formation. In order to convert a decimal number into binary, we will use modules operator in Java, represented by percentage sign (%). This is also known as remainder operator because it returns remainder of division operation, for example 5%2 will return 1, while 7%4 will return 3. Since binary is a base 2 number system, we will divide each digit of decimal number with 2 and collect remainder. Logic of converting a decimal number to binary is encapsulated inside toBinary(int number) method, which takes a decimal number and returns a byte array containing bits of binary equivalent. By the way you can use technique mentioned in this article to also convert a decimal number to octal and hexadecimal systems, but there are couple of more ways to do that, as shown in this article.
Read more ยป

Read: Decimal to Binary Conversion in Java

Topic: A Template for Formulating Great Sprint Goals Previous Topic   Next Topic Topic: Choosing a leader like an agilist

Sponsored Links



Google
  Web Artima.com   

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