Last active
February 14, 2024 19:09
-
-
Save sadedv/ee4b5835c0ae609f68e0 to your computer and use it in GitHub Desktop.
Перевести число в различные системы счисления - Java (в шестнадцатиричную, бинарную (двоичную)) Integer to Binary, to Hex and to Octal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Main { | |
public static void main(String[] args) { | |
Integer number = 255; | |
// Бинарный формат числа | |
String convert = Integer.toBinaryString(number); | |
System.out.println(convert); | |
// Восьмиричная форма | |
convert = Integer.toOctalString(number); | |
System.out.println(convert); | |
// Шеснадцатиричная форма | |
convert = Integer.toHexString(number).toUpperCase(); | |
System.out.println(convert); | |
} | |
} |
Фигня
BigInteger num2 = new BigInteger(new BigInteger(number2.toString()).toString(16), 16);
как вариант
спасибо, помогло
спасибо)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Если число нецелого типа?