Saturday, July 23, 2016

Konversi String Ke Dalam ASCII,BINER Dengan Java

Contoh program kali ini kita rubah String menjadi ASCII dan BINER, berikut contoh programnya Nama file :  konvesi_Ascii_Biner.java im... thumbnail 1 summary

Contoh program kali ini kita rubah String menjadi ASCII dan BINER, berikut contoh programnya

Nama file :  konvesi_Ascii_Biner.java

import java.io.IOException;
import java.util.Scanner;
public class konversi_Ascii_Biner {
    public static void main(String[] args) throws IOException {
        String d = "";
        Scanner scn = new Scanner(System.in);
        System.out.print("Masukkan kata atau karakter : ");
        d = scn.next();
        char[] arrCharStr = d.toCharArray();
         System.out.println(" ");
        System.out.println("==Bilangan ASCII==");
        for (char e : arrCharStr) 
        {
            System.out.println(e+" = "+(int)e);}
            System.out.println("\n==Biner==");
            for (char e : arrCharStr) {
            System.out.println(e+" = 0"+Integer.toBinaryString(e));}
            System.out.println("\n== Biner - ASCII - Char ==");
            for (char e : arrCharStr) 
            {
                String bin = "0"+Integer.toBinaryString(e);
                int ascii = Integer.parseInt(bin,2);
                char kar = (char) ascii;
                System.out.println(bin + " :: "+ ascii +" :: "+kar);}
 }
 }

Output

Masukkan kata atau karakter : ngejava.com

==Bilangan ASCII==
n = 110
g = 103
e = 101
j = 106
a = 97
v = 118
a = 97
. = 46
c = 99
o = 111
m = 109

==Biner==
n = 01101110
g = 01100111
e = 01100101
j = 01101010
a = 01100001
v = 01110110
a = 01100001
. = 0101110
c = 01100011
o = 01101111
m = 01101101

==Konversi Biner - ASCII==
01101110 :: 110 :: n
01100111 :: 103 :: g
01100101 :: 101 :: e
01101010 :: 106 :: j
01100001 :: 97 :: a
01110110 :: 118 :: v
01100001 :: 97 :: a
0101110 :: 46 :: .
01100011 :: 99 :: c
01101111 :: 111 :: o
01101101 :: 109 :: m
BUILD SUCCESSFUL (total time: 8 seconds)

Selamat mencoba, semoga bermanfaat ...

No comments

Post a Comment