Non-decimal radices/Output: Difference between revisions

Add source for Rust
(Add source for Rust)
Line 1,209:
=={{header|Phixmonti}}==
<lang Phixmonti>33 for
dup "decimal: " print print " bin: " print 8 int>bit print nl
endfor</lang>
 
Line 1,284:
Binary (b), Octal (o), Decimal (d), and Hexadecimal (X and x) are supported by the [http://www.python.org/dev/peps/pep-3101/ format]method of a string
<div style="height:30ex;overflow:scroll"><lang python>>>> for n in range(34):
print " {0:6b} {1:3o} {2:2d} {3:2X}".format(n, n, n, n)
#The following would give the same output, and,
#due to the outer brackets, works with Python 3.0 too
#print ( " {n:6b} {n:3o} {n:2d} {n:2X}".format(n=n) )
 
0 0 0 0
1 1 1 1
Line 1,329:
Octal (o), Decimal (d), and Hexadecimal (X and x), but not binary are supported by the string modulo operator, %:
<lang python>for n in range(34):
print " %3o %2d %2X" % (n, n, n)</lang>
 
----
Line 1,599:
100.to_s(36) => 2s
</div>
 
=={{header|Rust}}==
<lang Rust>fn main() {
// To render the number as string, use format! macro instead
println!("Binary: {:b}", 0xdeadbeefu32);
println!("Binary with 0b prefix: {:#b}", 0xdeadbeefu32);
println!("Octal: {:o}", 0xdeadbeefu32);
println!("Octal with 0o prefix: {:#o}", 0xdeadbeefu32);
println!("Decimal: {}", 0xdeadbeefu32);
println!("Lowercase hexadecimal: {:x}", 0xdeadbeefu32);
println!("Lowercase hexadecimal with 0x prefix: {:#x}", 0xdeadbeefu32);
println!("Uppercase hexadecimal: {:X}", 0xdeadbeefu32);
println!("Uppercase hexadecimal with 0x prefix: {:#X}", 0xdeadbeefu32);
}</lang>
 
=={{header|Run BASIC}}==
<lang runbasic>
print asc("X") ' convert to ascii
print chr$(169) ' ascii to character
print dechex$(255) ' decimal to hex
print hexdec("FF") ' hex to decimal
print str$(467) ' decimal to string
print val("27") ' string to decimal
</lang>
 
Line 1,803 ⟶ 1,817:
=={{header|Yabasic}}==
<lang Yabasic>for i = 1 to 33
print "decimal: ", i, " hex: ", hex$(i), " bin: ", bin$(i)
next
</lang>
Anonymous user