Skip to content

Instantly share code, notes, and snippets.

Avatar
💻
Coding

Luis Cabrera Benito parzibyte

💻
Coding
View GitHub Profile
View mcm.java
public static int minimoComunMultiplo(int a, int b) {
// Y ahora aplicamos la fórmula que dice:
// MCM(a, b) = (a * b) / MCD(a, b)
return (a * b) / maximoComunDivisor(a, b);
}
View mcd.java
public static int maximoComunDivisor(int a, int b) {
int temporal;//Para no perder b
while (b != 0) {
temporal = b;
b = a % b;
a = temporal;
}
return a;
}
View mcd.java
public class Main {
public static void main(String[] args) {
int a = 50;
int b = 120;
int mcd = maximoComunDivisor(a, b);
System.out.printf("El MCD de %d y %d es %d\n", a, b, mcd);
int mcdRecursivo = maximoComunDivisorRecursivo(a, b);
System.out.printf("El MCD de %d y %d (con recursividad) es %d\n", a, b, mcdRecursivo);
}
View mcdRecursivo.java
public static int maximoComunDivisorRecursivo(int a, int b) {
if (b == 0) return a;
return maximoComunDivisorRecursivo(b, a % b);
}
View mcd.java
public static int maximoComunDivisor(int a, int b) {
int temporal;//Para no perder b
while (b != 0) {
temporal = b;
b = a % b;
a = temporal;
}
return a;
}
View translator.java
/*
____ _____ _ _ _
| _ \ | __ \ (_) | | |
| |_) |_ _ | |__) |_ _ _ __ _____| |__ _ _| |_ ___
| _ <| | | | | ___/ _` | '__|_ / | '_ \| | | | __/ _ \
| |_) | |_| | | | | (_| | | / /| | |_) | |_| | || __/
|____/ \__, | |_| \__,_|_| /___|_|_.__/ \__, |\__\___|
__/ | __/ |
|___/ |___/
View use.java
public static void main(String[] args) {
String originalText = "parzibyte.me";
System.out.println("Original text: " + originalText);
String translatedText = textToBinary(originalText);
System.out.println("In binary, it is: " + translatedText);
System.out.println("-----------------");
View binaryToText.java
public static String binaryToText(String binaryText) {
String[] binaryNumbers = binaryText.split(" ");
String text = "";
for (String currentBinary : binaryNumbers) {
int decimal = binaryToDecimal(currentBinary);
char letra = (char) decimal;
text += letra;
}
View textToBinary.java
public static String textToBinary(String originalText) {
String binaryText = "";
for (int i = 0; i < originalText.length(); i++) {
char currentChar = originalText.charAt(i);
int ascii = (int) currentChar;
String binary = decimalToBinary(ascii);
binaryText += binary + " ";
}
return binaryText;
}
View convert.java
public static int binaryToDecimal(String binary) {
int decimal = 0;
int position = 0;
for (int x = binary.length() - 1; x >= 0; x--) {
// Saber si es 1 o 0; primero asumimos que es 1 y abajo comprobamos
short digit = 1;
if (binary.charAt(x) == '0') {
digit = 0;
}
double multiplier = Math.pow(2, position);
You can’t perform that action at this time.