quarta-feira, 16 de junho de 2010

Java + Tabela de Decimal, Binário e Hexadecimal

P/ quem está na faculdade, tendo matemática, é bom saber essa tabela de cor , pelo menos até o 10 :)

Segue codigo JAVA p/ gerar tabela de "Decimal, Binário e Hexadecimal


/*
  Professor :   
  Version 1.0 
Created by Mario Cezzare mcezzare@gmail.com  on  03/04/2010
Faculdade Veris IBTA : Turma 1ADSI / 2010
// 
 * Apostila XXX
 * ALG n : 1
 * CAPITULO: 
 * PAGINA :    
 * EXERCICIO : XX
 * 
 * 
EXERCICIO 
/ estudo de math 
 * mostra tabela de Decimal, Binario e Hexadecimal de 1 a 100
 * */ 

import java.lang.*;
import java.io.*;

public class TabelaDBH {

public static void main(String args[]) throws IOException{ 
int i= 0
System.out.println("Decimal\t|\tBinario\t|\tHexa" );
System.out.println();
for (i=0;i<=100;i++){
String by = Integer.toBinaryString(i); // System.out.println("Binary: " + by);
String hex = Integer.toHexString(i);
System.out.println(i +"\t|\t"+by + "\t|\t" + hex);
}
}
}




-------------- Resultado  deve ser:-------------------

Decimal | Binario | Hexa

0 | 0 | 0
1 | 1 | 1
2 | 10 | 2
3 | 11 | 3
4 | 100 | 4
5 | 101 | 5
6 | 110 | 6
7 | 111 | 7
8 | 1000 | 8
9 | 1001 | 9
10 | 1010 | a
11 | 1011 | b
12 | 1100 | c
13 | 1101 | d
14 | 1110 | e
15 | 1111 | f
16 | 10000 | 10
17 | 10001 | 11
18 | 10010 | 12
19 | 10011 | 13
20 | 10100 | 14
21 | 10101 | 15
22 | 10110 | 16
23 | 10111 | 17
24 | 11000 | 18
25 | 11001 | 19
26 | 11010 | 1a
27 | 11011 | 1b
28 | 11100 | 1c
29 | 11101 | 1d
30 | 11110 | 1e
31 | 11111 | 1f
32 | 100000 | 20
33 | 100001 | 21
34 | 100010 | 22
35 | 100011 | 23
36 | 100100 | 24
37 | 100101 | 25
38 | 100110 | 26
39 | 100111 | 27
40 | 101000 | 28
41 | 101001 | 29
42 | 101010 | 2a
43 | 101011 | 2b
44 | 101100 | 2c
45 | 101101 | 2d
46 | 101110 | 2e
47 | 101111 | 2f
48 | 110000 | 30
49 | 110001 | 31
50 | 110010 | 32
51 | 110011 | 33
52 | 110100 | 34
53 | 110101 | 35
54 | 110110 | 36
55 | 110111 | 37
56 | 111000 | 38
57 | 111001 | 39
58 | 111010 | 3a
59 | 111011 | 3b
60 | 111100 | 3c
61 | 111101 | 3d
62 | 111110 | 3e
63 | 111111 | 3f
64 | 1000000 | 40
65 | 1000001 | 41
66 | 1000010 | 42
67 | 1000011 | 43
68 | 1000100 | 44
69 | 1000101 | 45
70 | 1000110 | 46
71 | 1000111 | 47
72 | 1001000 | 48
73 | 1001001 | 49
74 | 1001010 | 4a
75 | 1001011 | 4b
76 | 1001100 | 4c
77 | 1001101 | 4d
78 | 1001110 | 4e
79 | 1001111 | 4f
80 | 1010000 | 50
81 | 1010001 | 51
82 | 1010010 | 52
83 | 1010011 | 53
84 | 1010100 | 54
85 | 1010101 | 55
86 | 1010110 | 56
87 | 1010111 | 57
88 | 1011000 | 58
89 | 1011001 | 59
90 | 1011010 | 5a
91 | 1011011 | 5b
92 | 1011100 | 5c
93 | 1011101 | 5d
94 | 1011110 | 5e
95 | 1011111 | 5f
96 | 1100000 | 60
97 | 1100001 | 61
98 | 1100010 | 62
99 | 1100011 | 63
100 | 1100100 | 64

Nenhum comentário: