Skip to content

Instantly share code, notes, and snippets.

@sadedv
Last active February 14, 2024 19:09
Show Gist options
  • Star 10 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save sadedv/ee4b5835c0ae609f68e0 to your computer and use it in GitHub Desktop.
Save sadedv/ee4b5835c0ae609f68e0 to your computer and use it in GitHub Desktop.
Перевести число в различные системы счисления - Java (в шестнадцатиричную, бинарную (двоичную)) Integer to Binary, to Hex and to Octal
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);
}
}
@gaussfff
Copy link

ncie1

@leovegas
Copy link

thanks

@kastricyn
Copy link

Если число нецелого типа?

Copy link

ghost commented Apr 3, 2020

Фигня

@Kox-kex
Copy link

Kox-kex commented Jun 17, 2020

BigInteger num2 = new BigInteger(new BigInteger(number2.toString()).toString(16), 16);
как вариант

@aka56kg
Copy link

aka56kg commented Dec 23, 2020

спасибо, помогло

@shvetsovart
Copy link

спасибо)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment