Communication with the aliens
Objectives
The objectives of this work:
- Handling (declaration, initialization and conversion) of variables
- Understanding of digital and Boolean expressions
- Use select statements (if / else)
- Using loops
Presentation of the problem
You are hired by NASA that has just come into contact with extraterrestrials.
The aliens are trying to communicate with us by sending us numerical values, and
we reply.
We are familiar with the base 10, which is part of our daily lives. For IT
Off-pair that you are, the base 2 has no secrets for you. Similarly for
8 and hexadecimal bases, 16. But what happens if we express numbers in base 23, 34?
NASA asks you to make a program that allows the conversion of number in
base 10 numbers to other bases whatsoever. Your program will be called
Alien.java
Basic knowledge on converting numbers
What is a digital database?
Each number is written are expressed in a precise numerical basis, normally
base 10. If we express the number 14, expressed exactly does one?
Exponent of 10: 1 0
Number: 1 4
Thus, the number 14 comes from: 14 = 1_101 4_100
If we take another example, the number 1237, that number is expressed by the table
follows:
Superscript 10: 3 2 1 0
Quantity: 1 2 3 7
Thus, the number 1237 comes from: 1237 1_103 2_102 3_101 7_100 =
Thus, each number represents a form a multiplication factor of a
outlining its basic digital.
What happens if we want to express the number 17 (base 10) in the following basis:
- Base-2: 17 = (10001) 2 = 1_24 0_23 0_22 0_21 1_20
- Base 8 17 = (00 021) 8 = 0_84 0_83 0_82 2_81 1_80
- 16 base 17 = (00011) 0_164 0_163 0_162 16 = 1_161 1_160
Thus, the numbers change completely how to write, depending on the basis
digital is used.
The number of bits
The number of bits determines the number of digits will build the number you
want to write. For example, if you write 10-bit number 147, would give the results
following:
- In base 10: 0000 0147
- Base 2: 147 = (10010011) 2
- Base 8: 147 = (00000223) 8
- In base 16: 147 = (00000093) 16
What if the number to enter in a bit over 9?
You're already familiar with the base 16, hexadecimal. The value for each
positions in the base hexadecimal numbers can be between 0 and 15. Unfortunately
you can not write a single position values 10,11,12,13,14 and 15 (since they are
composed of two numbers). In the case of the base 16, it uses numbers and letters
following, to express the values:
Values: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
Corresponding character: 0 1 2 3 4 5 6 7 8 9 ABCDEF
So if you want to write the number 250 in base 16 with 3 bits, obtains the following number:
(250) 10 = (0FA) 16 162 15 = 0 _ _ _ 161 10 160
F = 0 _ 162 _ 160 _ 161 A
So, in your program, you must express the values above 10 with
letters, not figures.
4 Operation of your program
You should write a program that performs the following steps
1. Ask the user an nb, POSITIVE and base 10, it wishes to convert
2. Prompts the user base into which convert the numbers nb
3. Prompts the user with how many bits it wants to write the number
4. Print the number converted in its new base, with the desired number of bits
Your program will convert the numbers selected by the user until the latter
between a negative number. In this case, you record a message telling the user
communication with the aliens ended ... :) You do not have to
convert negative numbers.
Example execution
Here is an example of running your program:
Enter the number to be converted
147
Enter the base conversion (between 2 and 41)
16
Enter the number of bits encoding
8
The number converted:
00000093
Enter the number to be converted
18
Enter the base conversion (between 2 and 41)
14
3
Enter the number of bits encoding
4
The number converted:
0014
Enter the number to be converted
48
Enter the base conversion (between 2 and 41)
2
Enter the number of bits encoding
10
The number converted:
0000110000
Enter the number to be converted
-1
Communication ended
5 Restriction to User
Checks should be made to verify that the user input are
valid:
The bases selected by the user should be between 2 and 35, in order to express
numbers with numbers from 0-9 and from A to Z.
The number to be translated should be expressed in the number of bits requested by the user.
If one of above conditions is not met, your program must indicate to the user via an error message that the entry is invalid.
Here's an example:
Enter the number to be converted
100
Enter the base conversion (between 2 and 41)
2
Enter the number of bits encoding
3
Unable to express the number 100 in 3 digit
Enter the number to be converted
100
Enter the base conversion (between 2 and 41)
59
The base is invalid
4
You can assume that the user will always enter the whole ...
Criteria for termination of your program (stops when a negative number is entered)
Here's what you must submit:
- Your pseudo-code (Required)
- Your code, which will be in the file: Alien.java
Put the answer on the forum (The pseudo-code and code Java)
Pour la version francaise, veuiller downloader le document si dessous:
http://aezir.com/download/Alien.doc