Initial data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 72d218235f
commit f23f22d71c
199087 changed files with 3378941 additions and 0 deletions

View file

@ -0,0 +1,5 @@
---
category:
- Simple
from: http://rosettacode.org/wiki/Literals/Integer
note: Basic language learning

View file

@ -0,0 +1,16 @@
Some programming languages have ways of expressing integer literals in bases other than the normal base ten.
;Task:
Show how integer literals can be expressed in as many bases as your language allows.
Note:   this should '''not''' involve the calling of any functions/methods, but should be interpreted by the compiler or interpreter as an integer written to a given base.
Also show any other ways of expressing literals, e.g. for different types of integers.
;Related task:
*   [[Literals/Floating point]]
<br><br>

View file

@ -0,0 +1,7 @@
print(255) // decimal literal
print(0000'00FF) // hexadecimal literal
print(00'FF) // short hexadecimal literal
print(F'F) // ultrashort (single-byte) hexadecimal literal
print(377o) // octal literal
print(1111'1111b) // binary literal
print(255'000) // decimal literal

View file

@ -0,0 +1,5 @@
;These are all equivalent, and each load the constant value 65 into the accumulator.
LDA #$41
LDA #65
LDA #%01000001
LDA #'A'

View file

@ -0,0 +1,5 @@
;These are all equivalent:
MOVE.B #$41,D0
MOVE.B #65,D0
MOVE.B #%01000001,D0
MOVE.B #'A',D0

View file

@ -0,0 +1,4 @@
MOV AX,4C00h
MOV BX,%1111000011110000
MOV CX,0xBEEF
MOV DL,35

View file

@ -0,0 +1,71 @@
.equ STDOUT, 1
.equ SVC_WRITE, 64
.equ SVC_EXIT, 93
.text
.global _start
_start:
stp x29, x30, [sp, -16]!
mov x29, sp
mov x0, #123 // decimal
bl print_uint64
mov x0, #0b01111011 // binary
bl print_uint64
mov x0, #0173 // octal
bl print_uint64
mov x0, #0x7b // hexadecimal
bl print_uint64
mov x0, #'{ // ascii value
bl print_uint64
mov x0, #'\{ // ascii value in another way
bl print_uint64
ldp x29, x30, [sp], 16
mov x0, #0
b _exit // exit(0);
// void print_uint64(uint64_t x) - print an unsigned integer in base 10.
print_uint64:
// x0 = remaining number to convert
// x1 = pointer to most significant digit
// x2 = 10
// x3 = x0 / 10
// x4 = x0 % 10
// compute x0 divmod 10, store a digit, repeat if x0 > 0
ldr x1, =strbuf_end
mov x2, #10
1: udiv x3, x0, x2
msub x4, x3, x2, x0
add x4, x4, #48
mov x0, x3
strb w4, [x1, #-1]!
cbnz x0, 1b
// compute the number of digits to print, then call write()
ldr x3, =strbuf_end_newline
sub x2, x3, x1
mov x0, #STDOUT
b _write
.data
strbuf:
.space 31
strbuf_end:
.ascii "\n"
strbuf_end_newline:
.align 4
.text
//////////////// system call wrappers
// ssize_t _write(int fd, void *buf, size_t count)
_write:
stp x29, x30, [sp, -16]!
mov x8, #SVC_WRITE
mov x29, sp
svc #0
ldp x29, x30, [sp], 16
ret
// void _exit(int retval)
_exit:
mov x8, #SVC_EXIT
svc #0

View file

@ -0,0 +1,40 @@
main:(
SHORT SHORT INT ssdec = SHORT SHORT 727,
sshex = ABS SHORT SHORT 16r2d7,
ssoct = ABS SHORT SHORT 8r1327,
ssbin = ABS SHORT SHORT 2r1011010111;
SHORT INT sdec = SHORT 727,
shex = ABS SHORT 16r2d7,
soct = ABS SHORT 8r1327,
sbin = ABS SHORT 2r1011010111;
INT dec = 727,
hex = ABS 16r2d7,
oct = ABS 8r1327,
bin = ABS 2r1011010111;
LONG INT ldec = LONG 727,
lhex = ABS LONG 16r2d7,
loct = ABS LONG 8r1327,
lbin = ABS LONG 2r1011010111;
CO
LONG LONG INT lldec = LONG LONG 727,
llhex = ABS LONG LONG 16r2d7,
lloct = ABS LONG LONG 8r1327,
llbin = ABS LONG LONG 2r1011010111
# etc ... #
END CO
print(("SHORT SHORT INT:", ssdec, sshex, ssoct, ssbin, new line));
print((" SHORT INT:", sdec, shex, soct, sbin, new line));
print((" INT:", dec, hex, oct, bin, new line));
print((" LONG INT:", ldec, lhex, loct, lbin, new line))
CO LONG LONG INT not supported by ELLA ALGOL 68RS
print(("LONG LONG INT:", new line, lldec, new line, llhex, new line, lloct, new line, llbin, new line))
# etc ... #
END CO
)

View file

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

View file

@ -0,0 +1,137 @@
/* ARM assembly Raspberry PI */
/* program integer.s */
/* Constantes */
.equ STDOUT, 1 @ Linux output console
.equ EXIT, 1 @ Linux syscall
.equ WRITE, 4 @ Linux syscall
/*********************************/
/* Initialized data */
/*********************************/
.data
iNumberBinaire: .int 0b1100100
iNumberOctal: .int 0144
iNumberDecimal: .int 100
iNumberHexa: .int 0x64
szMessResult: .ascii "Resultat = " @ message result
sMessValeur: .fill 12, 1, ' '
.asciz "\n"
/*********************************/
/* UnInitialized data */
/*********************************/
.bss
/*********************************/
/* code section */
/*********************************/
.text
.global main
main: @ entry of program
push {fp,lr} @ saves 2 registers
ldr r0,iAdriNumberBinaire @ number address
ldr r0,[r0] @ load number
ldr r1,iAdrsMessValeur
bl conversion10 @ call function with 2 parameter (r0,r1)
ldr r0,iAdrszMessResult
bl affichageMess @ display message
ldr r0,iAdriNumberOctal
ldr r0,[r0]
ldr r1,iAdrsMessValeur
bl conversion10 @ call function with 2 parameter (r0,r1)
ldr r0,iAdrszMessResult
bl affichageMess @ display message
ldr r0,iAdriNumberDecimal
ldr r0,[r0]
ldr r1,iAdrsMessValeur
bl conversion10 @ call function with 2 parameter (r0,r1)
ldr r0,iAdrszMessResult
bl affichageMess @ display message
ldr r0,iAdriNumberHexa
ldr r0,[r0]
ldr r1,iAdrsMessValeur
bl conversion10 @ call function with 2 parameter (r0,r1)
ldr r0,iAdrszMessResult
bl affichageMess @ display message
100: @ standard end of the program
mov r0, #0 @ return code
pop {fp,lr} @restaur 2 registers
mov r7, #EXIT @ request to exit program
svc #0 @ perform the system call
iAdriNumberBinaire: .int iNumberBinaire
iAdriNumberOctal: .int iNumberOctal
iAdriNumberDecimal: .int iNumberDecimal
iAdriNumberHexa: .int iNumberHexa
iAdrsMessValeur: .int sMessValeur
iAdrszMessResult: .int szMessResult
/******************************************************************/
/* display text with size calculation */
/******************************************************************/
/* r0 contains the address of the message */
affichageMess:
push {r0,r1,r2,r7,lr} /* save registres */
mov r2,#0 /* counter length */
1: /* loop length calculation */
ldrb r1,[r0,r2] /* read octet start position + index */
cmp r1,#0 /* if 0 its over */
addne r2,r2,#1 /* else add 1 in the length */
bne 1b /* and loop */
/* so here r2 contains the length of the message */
mov r1,r0 /* address message in r1 */
mov r0,#STDOUT /* code to write to the standard output Linux */
mov r7, #WRITE /* code call system "write" */
svc #0 /* call systeme */
pop {r0,r1,r2,r7,lr} /* restaur des 2 registres */
bx lr /* return */
/******************************************************************/
/* Converting a register to a decimal */
/******************************************************************/
/* r0 contains value and r1 address area */
conversion10:
push {r1-r4,lr} /* save registers */
mov r3,r1
mov r2,#10
1: @ start loop
bl divisionpar10 @ r0 <- dividende. quotient ->r0 reste -> r1
add r1,#48 @ digit
strb r1,[r3,r2] @ store digit on area
sub r2,#1 @ previous position
cmp r0,#0 @ stop if quotient = 0 */
bne 1b @ else loop
@ and move spaves in first on area
mov r1,#' ' @ space
2:
strb r1,[r3,r2] @ store space in area
subs r2,#1 @ @ previous position
bge 2b @ loop if r2 >= zéro
100:
pop {r1-r4,lr} @ restaur registres
bx lr @return
/***************************************************/
/* division par 10 signé */
/* Thanks to http://thinkingeek.com/arm-assembler-raspberry-pi/*
/* and http://www.hackersdelight.org/ */
/***************************************************/
/* r0 dividende */
/* r0 quotient */
/* r1 remainder */
divisionpar10:
/* r0 contains the argument to be divided by 10 */
push {r2-r4} /* save registers */
mov r4,r0
ldr r3, .Ls_magic_number_10 /* r1 <- magic_number */
smull r1, r2, r3, r0 /* r1 <- Lower32Bits(r1*r0). r2 <- Upper32Bits(r1*r0) */
mov r2, r2, ASR #2 /* r2 <- r2 >> 2 */
mov r1, r0, LSR #31 /* r1 <- r0 >> 31 */
add r0, r2, r1 /* r0 <- r2 + r1 */
add r2,r0,r0, lsl #2 /* r2 <- r0 * 5 */
sub r1,r4,r2, lsl #1 /* r1 <- r4 - (r2 * 2) = r4 - (r0 * 10) */
pop {r2-r4}
bx lr /* leave function */
.align 4
.Ls_magic_number_10: .word 0x66666667

View file

@ -0,0 +1,6 @@
BEGIN {
if ( (0x2d7 == 727) &&
(01327 == 727) ) {
print "true with GNU awk"
}
}

View file

@ -0,0 +1,5 @@
BEGIN {
x2d7 = "Goodbye, world!"
print 0x2d7 # gawk prints "727", nawk prints "0Goodbye, world!"
print 01327 # gawk prints "727", nawk prints "1327"
}

View file

@ -0,0 +1,9 @@
with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;
procedure Test_Literals is
begin
Put (16#2D7#);
Put (10#727#);
Put (8#1_327#);
Put (2#10_1101_0111#);
end Test_Literals;

View file

@ -0,0 +1,5 @@
if ((727 == 0x2d7) && (727 == 01327)) {
o_text("true\n");
} else {
o_text("false\n");
}

View file

@ -0,0 +1,3 @@
PROC main()
IF ($2d7 = 727) AND (%001011010111 = 727) THEN WriteF('true\n')
ENDPROC

View file

@ -0,0 +1,3 @@
num: 18966
print [num "->" type num]

View file

@ -0,0 +1,2 @@
If (727 == 0x2d7)
MsgBox true

View file

@ -0,0 +1,3 @@
Print: "0b11001101 = " ++ “0b11001101”;
Print: "0o755 = " ++ “0o755”;
Print: "0xDEADBEEF = " ++ “0xDEADBEEF”;

View file

@ -0,0 +1 @@
Print: "ZZr36 = " ++ “ZZr36”;

View file

@ -0,0 +1,3 @@
123
ᴇFACE
π101010

View file

@ -0,0 +1,3 @@
PRINT 17
PRINT &O21
PRINT &H11

View file

@ -0,0 +1,9 @@
print 17
print 0o21 #octal
print 0x11 #hexadecimal
print 0b10001 #binary
print FromRadix(17,10) #FromRadix(string, base)
print FromOctal(21)
print FromHex(11)
print FromBinary(10001)

View file

@ -0,0 +1,3 @@
PRINT 1234 : REM Decimal
PRINT &4D2 : REM Hexadecimal
PRINT %10011010010 : REM Binary

View file

@ -0,0 +1,2 @@
¯5
¯3000

View file

@ -0,0 +1 @@
1_000_000

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

@ -0,0 +1 @@
" ~"..@

View file

@ -0,0 +1,10 @@
#include <iostream>
int main()
{
std::cout << ( (727 == 0x2d7) &&
(727 == 01327) ? "true" : "false")
<< std::endl;
return 0;
}

View file

@ -0,0 +1,2 @@
int a = 42;
int b = 0x2a;

View file

@ -0,0 +1 @@
byte x = 500;

View file

@ -0,0 +1 @@
int x = 0b1100_1001_1111_0000;

View file

@ -0,0 +1,10 @@
#include <stdio.h>
int main(void)
{
printf("%s\n",
( (727 == 0x2d7) &&
(727 == 01327) ) ? "true" : "false");
return 0;
}

View file

@ -0,0 +1,2 @@
display B#10 ", " O#01234567 ", " -0123456789 ", "
H#0123456789ABCDEF ", " X#0123456789ABCDEF ", " 1;2;3;4

View file

@ -0,0 +1,2 @@
if 1234 = 1,2,3,4 then display "Decimal point is not comma" end-if
if 1234 = 1;2;3;4 then display "literals are equal, semi-colons ignored" end-if

View file

@ -0,0 +1,11 @@
user=> 2r1001
9
user=> 8r64
52
user=> 064
52
user=> 16r4b
75
user=> 0x4b
75
user=>

View file

@ -0,0 +1,2 @@
IF 37=$25 THEN PRINT "True"
IF 37=%00100101 THEN PRINT "True"

View file

@ -0,0 +1,8 @@
>(= 727 #b1011010111)
T
>(= 727 #o1327)
T
>(= 727 #x2d7)
T
>(= 727 #20r1g7)
T

View file

@ -0,0 +1,20 @@
import std.stdio, std.conv;
void main() {
writeln("oct: ", octal!777);
writeln("bin: ", 0b01011010);
writeln("hex: ", 0xBADF00D);
writeln("dec: ", 1000000000);
writeln("dec: ", 1_000_000_000);
writeln();
writeln(typeid(typeof(0)));
writeln(typeid(typeof(0u)));
// writeln(typeid(typeof(0l))); // 'l' suffix is deprecated
writeln(typeid(typeof(0L)));
writeln(typeid(typeof(0uL)));
writeln(typeid(typeof(0LU)));
writeln();
writefln("%x", 0xFEE1_BAD_CAFE_BABEuL);
}

View file

@ -0,0 +1,4 @@
$ decimal1 = 123490
$ decimal2 = %D123490
$ octal = %O12370
$ hex = %X1234AF0

View file

@ -0,0 +1,2 @@
var a : Integer := 42;
var b : Integer := $2a;

View file

@ -0,0 +1,4 @@
const
DEC_VALUE = 256; // decimal notation
HEX_VALUE = $100; // hexadecimal notation
BIN_VALUE = %100000000; // binary notation (since Delphi 10.4 version)

View file

@ -0,0 +1,2 @@
var a = 42
var b = 0x2a

View file

@ -0,0 +1,4 @@
42 // a decimal integer
#x2A // a hexadecimal integer
#o52 // an octal integer
#b101010 // a binary integer

View file

@ -0,0 +1,8 @@
? 256
# value: 256
? 0x100
# value: 256
? 0123
# syntax error: Octal is no longer supported: 0123

View file

@ -0,0 +1,16 @@
^|
| EMal internally uses 64 bit signed integers.
|^
int hex = 0xff # base16
int oct = 0o377 # base8
int bin = 0b11111111 # base2
int dec = 255 # base10
writeLine(hex)
writeLine(oct)
writeLine(bin)
writeLine(dec)
# here we check that they give the same value
writeLine(0b1011010111 == 0o1327 and
0o1327 == 0x2d7 and
0x2d7 == 727 and
727 == 0b1011010111)

View file

@ -0,0 +1,4 @@
PRINT(17)
PRINT(&21)
PRINT($11)
PRINT(%1001)

View file

@ -0,0 +1,4 @@
decimal = 57
hexadecimal = 0x39
print decimal
print hexadecimal

View file

@ -0,0 +1,7 @@
@public
run = fn () {
io.format("0xff : ~B~n", [0xff])
io.format("0xFF : ~B~n", [0xFF])
io.format("0o777 : ~B~n", [0o777])
io.format("0b1011: ~B~n", [0b1011])
}

View file

@ -0,0 +1,5 @@
123 -- decimal
-1_2_3 -- decimal
0x7b -- hexadecimal
0c173 -- octal
0b111_1011 -- binary

View file

@ -0,0 +1,2 @@
{NATURAL_8} 255
{INTEGER_64} 2_147_483_648

View file

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

View file

@ -0,0 +1,10 @@
1234 #=> 1234
1_000_000 #=> 1000000
0010 #=> 10
0b111 #=> 7
0o10 #=> 8
0x1f #=> 31
0B10 #=> syntax error before: B10
0X10 #=> syntax error before: X10
0xFF #=> 255

View file

@ -0,0 +1,5 @@
123 ;; decimal all Emacs
#b101 ;; binary Emacs 21 up, XEmacs 21
#o77 ;; octal Emacs 21 up, XEmacs 21
#xFF ;; hex Emacs 21 up, XEmacs 21
#3r210 ;; any radix 2-36 Emacs 21 up (but not XEmacs 21.4)

View file

@ -0,0 +1,8 @@
> 2#101.
5
> 101.
101
> 16#F.
15
> 36#3z.
143

View file

@ -0,0 +1,6 @@
printf(1,"Decimal:\t%d, %d, %d, %d\n",{-10,10,16,64})
printf(1,"Hex:\t%x, %x, %x, %x\n",{-10,10,16,64})
printf(1,"Octal:\t%o, %o, %o, %o\n",{-10,10,16,64})
printf(1,"Exponential:\t%e, %e, %e, %e\n",{-10,10,16,64.12})
printf(1,"Floating Point\t%3.3f, %3.3f, %+3.3f\n",{-10,10.2,16.25,64.12625})
printf(1,"Floating Point or Exponential: %g, %g, %g, %g\n",{10,16,64,123456789.123})

View file

@ -0,0 +1,3 @@
0b101 // = 5
0o12 // = 10
0xF // = 16

View file

@ -0,0 +1,8 @@
10y // 8-bit
'g'B // Character literals can be turned into unsigned 8-bit literals
10s // 16-bit
10l // 32-bit (suffix is optional)
10L // 64-bit
10I // Bigint (cannot be preceded by a 'u')
10un // Unsigned native int (used to represent pointers)

View file

@ -0,0 +1,4 @@
10 . ! decimal
0b10 . ! binary
-0o10 . ! octal
0x10 . ! hexadecimal

View file

@ -0,0 +1,2 @@
1,234,567 .
1,23,4,567 .

View file

@ -0,0 +1,7 @@
;; Fennel, like Lua, supports base 10 and hex literals (with a leading 0x).
1234 ;1234
0x1234 ;4660
;; Optionally, underscores can be used to split numbers into readable chunks.
123_456_789 ;123456789
0x1234_5678 ;305419896

View file

@ -0,0 +1,7 @@
HEX
FEEDFACE
2 BASE !
1011001
DECIMAL
1234
: mask var @ [ base @ hex ] 3fff and [ base ! ] var ! ;

View file

@ -0,0 +1,3 @@
1234 ( n )
123.4 ( l h )
123e4 ( F: n )

View file

@ -0,0 +1,4 @@
$feedface \ hexadecimal
&1234 \ decimal
%1001101 \ binary
'a \ base 256 (ASCII literal)

View file

@ -0,0 +1,11 @@
program IntegerLiteral
implicit none
integer, parameter :: dec = 727
integer, parameter :: hex = Z'2d7'
integer, parameter :: oct = O'1327'
integer, parameter :: bin = B'1011010111'
print *, dec, hex, oct, bin
end program IntegerLiteral

View file

@ -0,0 +1,20 @@
' FB 1.05.0 Win64
' The following all print 64 to the console
' integer literals of unspecified type - actual type is inferred from size or context (8, 16, 32 or 64 bit signed/unsigned)
Print 64 '' Decimal literal
Print &H40 '' Hexadecimal literal
Print &O100 '' Octal Literal
Print &B1000000 '' Binary literal
' integer literals of specific types
' Integer type is 4 bytes on 32 bit and 8 bytes on 64 bit platform
Print 64% '' Decimal signed 4/8 byte integer (Integer)
Print 64L '' Decimal signed 4 byte integer (Long)
Print 64& '' Decimal signed 4 byte integer (Long) - alternative suffix
Print 64LL '' Decimal unsigned 4 byte integer (ULong)
Print 64LL '' Decimal signed 8 byte integer (LongInt)
Print 64ULL '' Decimal unsigned 8 byte integer (ULongInt)
Sleep

View file

@ -0,0 +1,16 @@
123456789123456789 // (a number in base 10)
123_456_789_123_456_789 // (the same number in base 10 with underscores for readability)
1 quadrillion // (named numbers are fine in Frink.)
1ee39 // (exact exponent, an integer with exact value 10^39)
6.02214076ee23 // (exact exponent, Avogadro's number now defined as the exact integer 602214076000000000000000 )
100001000101111111101101\\2 // (a number in base 2)
1000_0100_0101_1111_1110_1101\\2 // (a number in base 2 with underscores for readability)
845FED\\16 // (a number in base 16... bases from 2 to 36 are allowed)
845fed\\16 // (The same number in base 16... upper or lowercase are allowed.)
845_fed\\16 // (a number in base 16 with underscores for readability)
FrinkRulesYou\\36 // (a number in base 36)
0x845fed // (Common hexadecimal notation)
0x845FED // (Common hexadecimal notation)
0xFEED_FACE // (Hexadecimal with underscores for readability)
0b100001000101111111101101 // (Common binary notation)
0b1000_0100_0101_1111_1110_1101 // (Binary with underscores for readability)

View file

@ -0,0 +1,8 @@
window 1
printf @" Decimal: %ld", 100
printf @" Hexadecimal: %x", 100
printf @" Octal: %o", 100
print @" Binary: "; bin$(100)
HandleEvents

View file

@ -0,0 +1,3 @@
# Only decimal integers, but of any length
31415926
1606938044258990275541962092341162602522202993782792835301376

View file

@ -0,0 +1,10 @@
package main
import "fmt"
func main() {
fmt.Println(727 == 0x2d7) // prints true
fmt.Println(727 == 01327) // prints true
fmt.Println(727 == 0b10110_10111) // prints true
fmt.Println(727 == '˗') // prints true
}

View file

@ -0,0 +1,5 @@
println 025 // octal
println 25 // decimal integer
println 25l // decimal long
println 25g // decimal BigInteger
println 0x25 // hexadecimal

View file

@ -0,0 +1 @@
? 0x1f

View file

@ -0,0 +1,4 @@
Prelude> 727 == 0o1327
True
Prelude> 727 == 0x2d7
True

View file

@ -0,0 +1,6 @@
# All equal to 15
println 15
println 000015 # Leading zeros are ignored
println 0b1111
println 0o17
println 0xf

View file

@ -0,0 +1,4 @@
U8 i; // 8 bit integer
U16 i; // 16 bit integer
U32 i; // 32 bit integer
U64 i; // 64 bit integer

View file

@ -0,0 +1,2 @@
U16 i = 727; // decimal
U16 i = 0x2d7; // hexadecimal

View file

@ -0,0 +1,3 @@
PRINT 17
PRINT BIN(10001)
PRINT ORD(HEX$("11"))

View file

@ -0,0 +1,7 @@
procedure main()
L := [1, 2r10, 3r10, 4r10, 5r10, 6r10, 7r10, 8r10, 9r10, 10r10, 11r10, 12r10, 13r10, 14r10,
15r10, 16r10, 17r10, 18r10,19r10, 20r10, 21r10, 22r10, 23r10, 24r10, 25r10, 26r10, 27r10,
28r10, 29r10, 30r10, 31r10, 32r10, 33r10, 34r10, 35r10, 36r10]
every write(!L)
end

View file

@ -0,0 +1,3 @@
10b123 16b123 8b123 20b123 2b123 1b123 0b123 100b123 99 0 0bsilliness
1
123 291 83 443 11 6 3 10203 99 0 1 28

View file

@ -0,0 +1 @@
0 1 0 0 0 1 0 0 0 1 1 1 1

View file

@ -0,0 +1,5 @@
123456789123456789123456789 100000000000x
123456789123456789123456789 100000000000
16b100 10x
|ill-formed number

View file

@ -0,0 +1,2 @@
1e2 100r5
100 20

View file

@ -0,0 +1,6 @@
public class IntegerLiterals {
public static void main(String[] args) {
System.out.println( 727 == 0x2d7 &&
727 == 01327 );
}
}

View file

@ -0,0 +1,5 @@
public class BinaryLiteral {
public static void main(String[] args) {
System.out.println( 727 == 0b10_1101_0111 );
}
}

View file

@ -0,0 +1,3 @@
if ( 727 == 0x2d7 &&
727 == 01327 )
window.alert("true");

View file

@ -0,0 +1,2 @@
julia> 0b1011010111 == 0o1327 == 0x2d7 == 727
true

View file

@ -0,0 +1,28 @@
fun main() {
// signed integer literals
val d = 255 // decimal
val h = 0xff // hexadecimal (can use 0X instead of 0x)
val b = 0b11111111 // binary (can use 0B instead of 0b)
// signed long integer literals (cannot use l instead of L)
val ld = 255L // decimal
val lh = 0xffL // hexadecimal
val lb = 0b11111111L // binary
// unsigned integer literals (can use U instead of u)
val ud = 255u // decimal
val uh = 0xffu // hexadecimal
val ub = 0b11111111u // binary
// unsigned long integer literals (can use U instead of u)
val uld = 255uL // decimal
val ulh = 0xffuL // hexadecimal
val ulb = 0b11111111uL // binary
// implicit conversions
val ld2 = 2147483648 // decimal signed integer literal automatically converted to Long since it cannot fit into an Int
val ush : UShort = 0x7fu // hexadecimal unsigned integer literal automatically converted to UShort
val bd : Byte = 0b01111111 // binary signed integer literal automatically converted to Byte
println("$d $h $b $ud $uh $ub $ld $lh $lb $uld $ulh $ulb $ld2 $ush $bd")
}

View file

@ -0,0 +1,2 @@
42
0x2a

View file

@ -0,0 +1,18 @@
implement Command;
include "sys.m";
sys: Sys;
include "draw.m";
include "sh.m";
init(nil: ref Draw->Context, nil: list of string)
{
sys = load Sys Sys->PATH;
sys->print("%d\n", 2r1111); # binary
sys->print("%d\n", 8r17); # octal
sys->print("%d\n", 15); # decimal
sys->print("%d\n", 16rF); # hexadecimal
}

View file

@ -0,0 +1 @@
put 0x1 + 0xff

View file

@ -0,0 +1,11 @@
:- object(integers).
:- public(show/0).
show :-
write('Binary 0b11110101101 = '), write(0b11110101101), nl,
write('Octal 0o3655 = '), write(0o3655), nl,
write('Decimal 1965 = '), write(1965), nl,
write('Hexadecimal 0x7AD = '), write(0x7AD), nl.
:- end_object.

View file

@ -0,0 +1,6 @@
| ?- integers::show.
Binary 0b11110101101 = 1965
Octal 0o3655 = 1965
Decimal 1965 = 1965
Hexadecimal 0x7AD = 1965
yes

View file

@ -0,0 +1 @@
45, 0x45

View file

@ -0,0 +1,7 @@
Def ExpType$(x)=Type$(x)
Print ExpType$(12345678912345#)="Currency", 12345678912345#
Print ExpType$(123456789123456789123456@)="Decimal", 123456789123456789123456@
Print ExpType$(12&)="Long", 12&, 0xFFFFFFFF&=-1
Print ExpType$(12%)="Integer", 12%, 0xFFFF%=-1
\\ used for unsigned integers (but it is double)
Print ExpType$(0xFFFFFFFF)="Double", 0xFFFFFFFF=4294967295

View file

@ -0,0 +1,3 @@
eval(10) # base 10
eval(010) # base 8
eval(0x10) # base 16

View file

@ -0,0 +1,4 @@
eval(0b10) # base 2
eval(`0r2:10') # base 2
...
eval(`0r36:10') # base 36

View file

@ -0,0 +1,2 @@
> 11
ans = 11

View file

@ -0,0 +1,2 @@
> 0x11
ans = 17

View file

@ -0,0 +1,3 @@
hex2dec(s)
bin2dec(s)
base2dec(s,base)

View file

@ -0,0 +1,8 @@
int8(8)
uint8(8)
int16(8)
uint16(8)
int32(8)
uint32(8)
int64(8)
uint64(8)

Some files were not shown because too many files have changed in this diff Show more