How to Convert Binary to Decimal in java programming

preview_player
Показать описание
how to convert binary number to decimal in complete Java programming by easy ways ......
Рекомендации по теме
Комментарии
Автор

Dude, you just did my homework...thanks :-)

VS-eylf
Автор

this video is a whole meme lmaoooo. but good stuff, thanks!

diistruct
Автор

to all the video tutorials in the youtube this one is the shortest and easiest one for me. Thanks!

spade
Автор

package dec_to_binary;

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;



import Converter.Converter;


public class DEC_TO_BINARY extends JFrame{
public static void main(String[] args) {
String[] Options = {"String", "Numbers"};
JComboBox List = new JComboBox();
for(int i = 0; i < Options.length; i++){
List.addItem(Options[i]);

}

List.setBounds(25, 150, 150, 25);
JFrame frame = new JFrame();
JPanel panel = new JPanel();


JMenuBar menubar = new JMenuBar();
frame.setJMenuBar(menubar);
JMenu save_as = new JMenu("Save");
JMenu Help = new JMenu("Help");

JMenuItem save = new JMenuItem("Save Output As");
JMenuItem Errors_Help = new JMenuItem("Error Help");

save_as.add(save);
Help.add(Errors_Help);


menubar.add(save_as);
menubar.add(Help);


panel.setLayout(null);


panel.add(List);


JTextArea Input = new JTextArea();
Input.setBounds(200, 100, 230, 200);
panel.add(Input);


JScrollPane scroll = new JScrollPane(Input, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
panel.add(scroll);
scroll.setBounds(230, 100, 230, 200);



JTextArea Result = new JTextArea();
Result.setBounds(30, 250, 100, 100);
panel.add(Result);

JScrollPane scroll2 = new JScrollPane(Result, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
scroll2.setBounds(30, 250, 100, 80);
panel.add(scroll2);




JLabel Text1 = new JLabel("Converter Version 1");
Text1.setBounds(150, 30, 150, 50);
panel.add(Text1);


JButton Convert_Button = new JButton("Convert");
ActionListener(){
@Override
public void actionPerformed(ActionEvent e){

String Type =
if(Type == "Numbers"){
Converter Convert = new Converter();
int Decimal =
String output = Convert.Convert_Int(Decimal, Type);
Result.setText(output);

}
if(Type == "String"){
Converter Convert = new Converter();
String string = Input.getText();
String output = Convert.Convert_String(string, Type);
Result.setText(output);




}

}

});

Convert_Button.setBounds(0, 50, 100, 50);
panel.add(Convert_Button);

JLabel Answer_Label = new JLabel("Output :");
Answer_Label.setBounds(25, 200, 50, 50);
panel.add(Answer_Label);



frame.setTitle("Convert To Binary");
frame.setSize(new Dimension(500, 400));
frame.setResizable(false);


frame.setVisible(true);

}


}

package Converter;
import java.util.*;

public class Converter{
boolean Running = true;
public String Convert_String(String string, String Type){
List<String> string_list = new ArrayList<>();
Map<String, String> dictionary = new HashMap<String, String>();

dictionary.put("a", "01100001");
dictionary.put("b", "01100010");
dictionary.put("c", "01100011");
dictionary.put("d", "01100100");
dictionary.put("e", "01100101");
dictionary.put("f", "01100110");
dictionary.put("g", "01100111");
dictionary.put("h", "01101000");
dictionary.put("i", "01101001");
dictionary.put("j", "01101010");
dictionary.put("k", "01101011");
dictionary.put("l", "01101100");
dictionary.put("m", "01101101");
dictionary.put("n", "01101110");
dictionary.put("o", "01101111");
dictionary.put("p", "01110000");
dictionary.put("q", "01110001");
dictionary.put("r", "01110010");
dictionary.put("s", "01110011");
dictionary.put("t", "01110100");
dictionary.put("u", "01110101");
dictionary.put("v", "01110110");
dictionary.put("w", "01110111");
dictionary.put("x", "01111000");
dictionary.put("y", "01111001");
dictionary.put("z", "01111010");
dictionary.put(" ",

string = string.toLowerCase();
for(String letter : string.split("")){
String position = dictionary.get(letter);
string_list.add(position);
string_list.add("\n");





}

String Output = String.join("", string_list);
System.out.println(Output);

return Output;



}
public String Convert_Int(int Decimal, String Type){
List<String> Numbers = new ArrayList<>();
int Times = 0;
if(Decimal == 0)
{
Numbers.add("0");
String Output = String.join("", Numbers);
return Output;
}
while(Running)
{
if(Decimal % 2 == 1){
Times += 1;
Numbers.add("1");
Decimal = Decimal / 2;
}
if(Decimal % 2 == 0){
Times += 1;
Numbers.add("0");
Decimal = Decimal / 2;
}

if(Decimal <= 1){
Times += 1;
Running = false;
Numbers.add("1");

}


if(Times > 6){
Numbers.add("* ");
Numbers.add("\n");
Times = 0;

}


}


// Collections.sort(Numbers);
Collections.reverse(Numbers);

String Output = String.join("", Numbers);
System.out.println(Output);
return Output;

}


}

servantofourlordjesuschris
Автор

Did you really use let it go on a java programming video?  Really?

CJBurkey
Автор

I watched the video because of the song :)

aptucta
Автор

can you also do it the manual way? with 2^i * the number (1 or 0) ?!?!?

Knightfire
Автор

so many complains about the song in video, I mean just mute it.

spade
Автор

I don't understand how you type this slow

Josephshanks
Автор

This dude has such bad choice of English music i feel bad for him

asifchowdhury
join shbcf.ru