Skip to content

Instantly share code, notes, and snippets.

@jukbot
Created December 1, 2015 18:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jukbot/7cc4ac7097831adbae0c to your computer and use it in GitHub Desktop.
Save jukbot/7cc4ac7097831adbae0c to your computer and use it in GitHub Desktop.
import java.util.Scanner;
public class FunHexadecimal{
public static String letShift(String str , int n){
Scanner in = new Scanner(System.in);
int time;
switch(n)
{
case 0 : System.out.println("Why you don't play?");
break;
case 1 : System.out.println("Please input time you wand to shift");
time = in.nextInt();
for(int i = 1 ; i <= time ; i++)
{
str = 0 + str;
}
//return str.substring(0,str.length()-time);
break;
case -1 : System.out.println("Please input time you wand to shift");
time = in.nextInt();
for(int i = 1 ; i <= time ; i++)
{
str = str + 0;
}
//return str.substring(time,str.length());
break;
}
return str;
}
public static String winWin(int x){
String s = "" + x;
if(x == 15) s = "F";
if(x == 14) s = "E";
if(x == 13) s = "D";
if(x == 12) s = "C";
if(x == 11) s = "B";
if(x == 10) s = "A";
return s;
}
public static int funPower(int a , int b){
int sum = 1;
for(int i = 1 ; i <=b ; i++)
{
sum = sum*a;
}
return sum;
}
public static void main(String[]args){
Scanner in = new Scanner(System.in);
int hexin = 0,i;
String hex = in.nextLine() , s = "";
int lastdi = 0;
String x = "";
for(i = hex.length() - 1 ; i>=0 ; i-- )
{
s = ""+hex.charAt(i);
if(hex.charAt(i)== 'A') s = "10";
if(hex.charAt(i)== 'B') s = "11";
if(hex.charAt(i)== 'C') s = "12";
if(hex.charAt(i)== 'D') s = "13";
if(hex.charAt(i)== 'E') s = "14";
if(hex.charAt(i)== 'F') s = "15";
hexin = Integer.parseInt(s);
while(hexin > 0)
{
lastdi = hexin % 2;
x = x + lastdi;
hexin = hexin / 2;
}
}
System.out.println(x);
System.out.println("Do you want to shift?\nIf yes and shift right say 1\nIf no say 0\nIf yes and shift left say -1");
int shift = in.nextInt();
x = letShift(x, shift);
int div = x.length()%4;
if(div != 0)
{
for(i = 1 ; i <= 4-div; i++)
{
x = 0 + x;
}
}
System.out.println(x);
int j,bin,power,p =3,sum=0;
String boy = "";
for(i = 0 ; i+3 <= x.length(); i+=4)
{
for(j=0; j <=3 ;j++,p--)
{
power = funPower(2,p);
bin = Integer.parseInt(x.substring(i+j,i+j+1));
sum = sum + (bin*power);
}
boy = boy + winWin(sum);
}
System.out.println(boy);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment