September 2017 Update

This commit is contained in:
Ingy döt Net 2017-09-23 10:01:46 +02:00
parent bba7bfd280
commit ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions

View file

@ -0,0 +1,3 @@
begin
write( 16, number( #10 ) )
end.

View file

@ -0,0 +1,6 @@
' literal integers
PRINT 10
PRINT 010
PRINT 0x10
' C compiler dependent, GCC extension
PRINT 0b10

View file

@ -0,0 +1,35 @@
ibase = 2
b[10] = -1011010111
ibase = 11 /* 3 */
b[10] = -222221
ibase = 11 /* 4 */
b[10] = -23113
ibase = 11 /* 5 */
b[10] = -10402
ibase = 11 /* 6 */
b[10] = -3211
ibase = 11 /* 7 */
b[10] = -2056
ibase = 11 /* 8 */
b[10] = -1327
ibase = 11 /* 9 */
b[10] = -887
ibase = 11 /* 10 */
b[10] = -727
ibase = 11 /* 11 */
b[10] = -601
ibase = 11 /* 12 */
b[10] = -507
ibase = 11 /* 13 */
b[10] = -43C
ibase = 11 /* 14 */
b[10] = -39D
ibase = 11 /* 15 */
b[10] = -337
ibase = 11 /* 16 */
b[10] = -2D7
ibase = A
for (i = 2; i <= 16; i++) if (b[i] != -727) "Impossible!
"
quit

View file

@ -1,2 +1,2 @@
#var n := 1234. // decimal number
#var x := 1234h. // hexadecimal number
var n := 1234. // decimal number
var x := 1234h. // hexadecimal number

View file

@ -0,0 +1,17 @@
// version 1.0.6
fun main(args: Array<String>) {
val d = 255 // decimal integer literal
val h = 0xff // hexadecimal integer literal
val b = 0b11111111 // binary integer literal
val ld = 255L // decimal long integer literal (can't use l instead of L)
val lh = 0xffL // hexadecimal long integer literal (could use 0X rather than 0x)
val lb = 0b11111111L // binary long integer literal (could use 0B rather than 0b)
val sd : Short = 127 // decimal integer literal automatically converted to Short
val sh : Short = 0x7f // hexadecimal integer literal automatically converted to Short
val bd : Byte = 0b01111111 // binary integer literal automatically converted to Byte
println("$d $h $b $ld $lh $lb $sd $sh $bd")
}

View file

@ -0,0 +1,21 @@
see "Decimal literal = " + 1234 + nl
see "Hexadecimal literal = " + dec("4D2") + nl
see "Octal Literal = " + octal(668) + nl
see "Binary literal = " + bintodec("10011010010")
func bintodec(bin)
binsum = 0
for n=1 to len(bin)
binsum = binsum + number(bin[n]) *pow(2, len(bin)-n)
next
return binsum
func octal m
output = ""
w = m
while fabs(w) > 0
oct = w & 7
w = floor(w / 8)
output = string(oct) + output
end
return output

View file

@ -1,8 +1,6 @@
irb(main):001:0> 727 == 0b1011010111
=> true
irb(main):002:0> 727 == 0x2d7
=> true
irb(main):003:0> 727 == 01327
=> true
irb(main):001:0> 12345 == 12_345 # underscores are ignored; useful for keeping track of places
=> true
727 == 0b1011010111 # => true, binary
727 == 0x2d7 # => true, hex
727 == 0o1327 # => true, octal
727 == 01327 # => true, octal
12345 == 12_345 # => true underscores are ignored; useful for keeping track of places

View file

@ -0,0 +1,6 @@
10 // Decimal
0b10 // Binary
0x10 // Hexadecimal
0o10 // Octal
1_000 // Underscores may appear anywhere in the numeric literal for clarity
10_i32 // The type (in this case i32, a 32-bit signed integer) may also be appended.

View file

@ -0,0 +1,3 @@
123, 0d1_000
0x123, 0x12|34
0b1111|0000