Skip to content

Commit bbaceae

Browse files
authored
Add example of parsing hex and binary with to_number (souffle-lang#140)
1 parent dc26ef4 commit bbaceae

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

pages/docs/arguments.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,17 +78,21 @@ llo
7878
ld!
7979
```
8080

81-
Functor **to_number(*string*)** transforms a string representing a number to its associated number.
81+
Functor **to_number(*string*)** transforms a string representing a number to its associated number, it also recognises hex and binary numbers with a prefix.
8282
```prolog
8383
.decl tonumber(n:number)
8484
.output tonumber
8585
tonumber(n) :- n=to_number("123").
8686
tonumber(n) :- n=to_number("1534").
87+
tonumber(n) :- n=to_number("0xff").
88+
tonumber(n) :- n=to_number("0b111").
8789
```
8890
The output would be:
8991
```
9092
123
9193
1534
94+
255
95+
7
9296
```
9397
The reverse operation **to_string(*number*)** also exists, which turns a number to its string representation.
9498

0 commit comments

Comments
 (0)