python
python
data = 255
#Binary number
b = bin(data) # '0b11111111'
b = format(data, 'b') # '11111111'
#8 base
o = oct(data) # '0377'
o = format(data, 'o') # '377'
#Hexadecimal
x = hex(data) # '0xff'
x = format(data, 'x') # 'ff'
#Convert 255 to decimal and write the last digit in decimal
int_x = int(format(data, 'x')[-1], 16) # 15
PHP
PHP
$data = 255;
//Binary number
$b = decbin($data); // '11111111'
//8 base
$o = decoct($data); // '377'
//Hexadecimal
$x = dechex($data); // 'ff'
//Convert 255 to decimal and write the last digit in decimal
$int_x = hexdec(substr(dechex($data), -1)); // 15
Ruby
Ruby
data = 255
#Binary number
b = data.to_s(2) # '11111111'
#8 base
o = data.to_s(8) # '377'
#Hexadecimal
x = data.to_s(16) # 'ff'
#Convert 255 to decimal and write the last digit in decimal
int_x = data.to_s(16)[-1].to_i(16) # 15
Recommended Posts