1. 


/**
* Angewandte Mathematik, SS09, IFB 2C
* ACM Problem #446 (Kibbles "n" Bits "n" Bits "n" Bits)
* Link: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=6&page=show_problem&problem=387
*
* @author Christian Posselt
* @author Jonathan Schubert
* @version 1.0, 05/14/2009
*
* Status : Accepted
* Runtime: 0.076
*/
import java.util.*;
import java.io.*;

public class Main
{

private static final HashMap<String,Integer> toDez = new HashMap<String,Integer>();
private static final HashMap<Integer,String> toBase = new HashMap<Integer,String>();

public static void main(String... args) throws IOException
{
//setup conversion-maps
String[] valueString = new String[]{"0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F"};
int[] valueInt = new int[]{0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};

for(int i=0;i<16;i++)
{
toDez.put(valueString[i], valueInt[i]);
toBase.put(valueInt[i], valueString[i]);
}

//set up needed variables
StringBuilder builder = new StringBuilder();
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
int amount, x, y, z;
String xStr, yStr, line, operation;

//read-in amount of sets
line = reader.readLine();
amount = Integer.parseInt(line);

for(int i=1;i<=amount;i++)
{
line = reader.readLine();
StringTokenizer token = new StringTokenizer(line," ");

//read-in number and convert to Decimal
x = toDecimal(token.nextToken(),16);
operation = token.nextToken();
y = toDecimal(token.nextToken(),16);

z = operation.equals("+") ? x+y : x-y;

//convert input to binary with 13 positions
xStr = toBase(x,2);
yStr = toBase(y,2);

//add result to StringBuilder
builder.append(xStr + " " + operation + " " + yStr + " = " + z + "\n");
}

System.out.print(builder.toString());
}


//convert number to decimal system
private static int toDecimal(String userinput, int userbase)
{
int result = 0;
int fac = 1;
if(userinput.equals("0"))
return 0;
for(int i = userinput.length()-1; i >= 0; i --)
{
if(!toDez.containsKey(userinput.substring(i,i+1)))
return -1;

result+= toDez.get(userinput.substring(i,i+1))*fac;
fac *= userbase;
}
return result;
}

//convert number from decimal system to a other system
private static String toBase(int have, int base)
{
StringBuilder result = new StringBuilder();
int fac = 1;
int length = 0;

while(have >= 1)
{
result.insert(0, toBase.get(have%base));
have /= base;
fac *= base;
length++;
}

while(length<13)
{
result.insert(0, 0);
length++;
}

return result.toString();
}
}

2.

/* Angewandte Mathematik, SS09, IFB 2C
* ACM Problem #446 (Kibbles "n" Bits "n" Bits "n" Bits)
* Link: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=6&page=show_problem&problem=387
*
* @author Dennis Wilfert
* @author Johann Studt
* @version 1.0, 05/15/2009
*
* Status : Accepted
* Runtime: 0.088
*/
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;


public class Main {

public static void main(String[] args) throws NumberFormatException, IOException {

BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
// StringBuilder für die Ausgabe
StringBuilder output = new StringBuilder();

// Scanner zum auslesen der Werte
Scanner scanner = new Scanner(reader);

// Anzahl der Testfälle
int number = Integer.parseInt(reader.readLine());
// Erste Zahl
int s1;
// Zweite Zahl
int s2;
// String für die Binäre Zahl
String str;
// Char für + oder -
char chr;

while(number>0){

// Erste Zahl auslesen und ins Dezimalsystem umrechnen
s1 = scanner.nextInt(16);

chr = scanner.next().charAt(0);
// Zweite Zahl auslesen und ins Dezimalsystem umrechnen
s2 = scanner.nextInt(16);

// Erste Zahl als binären String Speichern
str = Long.toBinaryString(s1);
// Nuller vorne anhängen
for(int i=str.length(); i<13; i++)
output.append(0);

output.append(str);
output.append(" " + chr + " ");

// Zweite Zahl als binären String Speichern
str = Long.toBinaryString(s2);
// Muller vorne anhängen
for(int i=str.length(); i<13; i++)
output.append(0);

output.append(str);
output.append(" = ");

// Prüfen ob + oder -
if(chr=='-')
output.append(s1-s2);
else
output.append(s1+s2);

output.append("\n");

number--;
}

System.out.print(output);
}

}

3.

/**
* Angewandte Mathematik, SS09, IFB 2C
* ACM Problem #446 Kibbles n-bits
*
* @author David Leib
* @author Julius Tschannerl
* @author Umut Taskin
* @author Hidir Sayli
*
* @version 1.0, 03/23/2009
*
* Status : Accepted
* Runtime: 0.084
*/



import java.io.*;
import java.util.*;

class Main{

public static void main(String... args) throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int count = Integer.parseInt(br.readLine());
while (count-- > 0)
{
String line = br.readLine();
StringTokenizer st = new StringTokenizer(line);
int op1 = Integer.parseInt(st.nextToken(), 16);
String operator = st.nextToken();
int op2 = Integer.parseInt(st.nextToken(), 16);
int sum;
if (operator.equals("+"))
sum = op1+op2;
else
sum = op1-op2;
System.out.printf("%013d %s %013d = %d%n", Long.parseLong(Integer.toString(op1, 2)), operator, Long.parseLong(Integer.toString(op2, 2)), sum);
}
}
}


4.

/**
* Angewandte Mathematik, SS09, IFB 2C
* ACM Problem #446 Kibbles "n" Bits "n" Bits "n" Bits
* Link: http://uva.onlinejudge.org/external/4/446.pdf
*
* @author Franz Mathauser, Rolf Schirm, Markus Mohr
* @version 1.0, 5/18/2009
*
* Status : Accepted
* Runtime: 0.092
*/

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;


public class Main{

public static void main(String...args) throws IOException{

BufferedReader reader = new BufferedReader(new
InputStreamReader(System.in));
int count = Integer.parseInt(reader.readLine());

while(count-- > 0){
String line = reader.readLine();
String[] parts = line.split(" ");
int first = Integer.parseInt(parts[0], 16);
String binFirst = Integer.toBinaryString(first);
int second = Integer.parseInt(parts[2], 16);
String binSec = Integer.toBinaryString(second);
int sum;
if (parts[1].equals("+"))
sum = first + second;
else
sum = first - second;

String output = "";
for (int i = binFirst.length(); i < 13; i++)
output += "0";
output += binFirst+" "+parts[1]+" ";
for (int i = binSec.length(); i < 13; i++)
output += "0";
output += binSec+" = "+sum;
System.out.println(output);
}
}
}