Page 553 - Cs_withBlue_J_C11_Flipbook
P. 553
SAMPLE PROJECTS #Experiential Learning
#Coding & Computational Thinking
#Collaboration & Teamwork
#Communication
Project 1 Write a program to covert a decimal number to other base and vice versa according to user’s
choice.
a. Decimal to Others
1. Decimal to Binary
2. Decimal to Octal
3. Decimal to Hexadecimal
b. Others to Decimal
1. Binary to Decimal
2. Octal to Decimal
3. Hexadecimal to Decimal
1 import java.util.*;
2 class Convert_between_Dec_others
3 {
4 int num,counter;
5 Convert_between_Dec_others()
6 {
7 num=0;
8 counter=0;
9 }
10
11 void dec2bin(int num)
12 {
13 int binaryVal[] = new int[32];
14 int num1=num;
15 while (num > 0)
16 {
17 binaryVal[counter++] = num % 2;
18 num = num / 2;
19 }
20 System.out.print("Binary Value of " + num1 + " : " );
21 for (int i = counter - 1; i >= 0; i--)
551
Sample Projects 551

