Just another update
This commit is contained in:
parent
a25938f123
commit
00a190b0a6
6591 changed files with 94363 additions and 23227 deletions
|
|
@ -1,7 +1,6 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"math/big"
|
||||
"strconv"
|
||||
|
|
@ -15,27 +14,31 @@ func main() {
|
|||
|
||||
// ParseInt handles arbitrary bases from 2 to 36, and returns
|
||||
// a result of the requested size (64 bits shown here.)
|
||||
// If the base argument is zero the base is determined by prefix
|
||||
// as with math/big below.
|
||||
x64, _ := strconv.ParseInt("3c2", 19, 64)
|
||||
fmt.Println(x64)
|
||||
|
||||
// package bytes+fmt: allows direct conversion from strings
|
||||
// to integer types for bases 2, 8, 10, and 16.
|
||||
// (Fscanf and scanf are more common for reading from
|
||||
// files or stdin than for reading from strings.)
|
||||
fmt.Fscanf(bytes.NewBufferString("1101"), "%b", &x)
|
||||
// package fmt: allows direct conversion from strings, standard
|
||||
// input, or from an io.Reader (file, buffer, etc) to integer types
|
||||
// for bases 2, 8, 10, and 16 or to any type that implements the
|
||||
// fmt.Scanner interface (e.g. a big.Int).
|
||||
// (Fscanf and Scanf are more common for reading from
|
||||
// an io.Reader or stdin than Sscanf for reading from strings.)
|
||||
fmt.Sscanf("1101", "%b", &x)
|
||||
fmt.Println(x)
|
||||
|
||||
fmt.Fscanf(bytes.NewBufferString("15"), "%o", &x)
|
||||
fmt.Sscanf("15", "%o", &x)
|
||||
fmt.Println(x)
|
||||
|
||||
fmt.Fscanf(bytes.NewBufferString("13"), "%d", &x)
|
||||
fmt.Sscanf("13", "%d", &x)
|
||||
fmt.Println(x)
|
||||
|
||||
fmt.Fscanf(bytes.NewBufferString("d"), "%x", &x)
|
||||
fmt.Sscanf("d", "%x", &x)
|
||||
fmt.Println(x)
|
||||
|
||||
// package big: allows conversion from string to big integer.
|
||||
// any base from 2 to 16 can be specified as second parameter.
|
||||
// package math/big: allows conversion from string to big integer.
|
||||
// any base from 2 to 36 can be specified as second parameter.
|
||||
var z big.Int
|
||||
z.SetString("111", 3)
|
||||
fmt.Println(&z)
|
||||
|
|
@ -52,4 +55,9 @@ func main() {
|
|||
|
||||
z.SetString("0xd", 0) // 0x -> base 16
|
||||
fmt.Println(&z)
|
||||
|
||||
// As mentioned, a big.Int (or any type implementing fmt.Scanner)
|
||||
// can also be use with any of the fmt scanning functions.
|
||||
fmt.Sscanf("15", "%o", &z)
|
||||
fmt.Println(&z)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,26 +1,17 @@
|
|||
/*REXX program demonstrates REXX's ability to handle non-decimal radices*/
|
||||
/*┌────────────────────────────────────────────────────────────────────┐
|
||||
┌─┘ In REXX, there are no numeric-type variables (integer, float, real,└─┐
|
||||
│ logical, complex, double, etc), only character. Everything is stored │
|
||||
│ as a character string. Arithmetic is done almost exactly the way a │
|
||||
│ schoolchild would perform it. To add, align the two numbers up (right │
|
||||
│ justified, with the decimal being the pivot) and simply add the columns│
|
||||
│ up, noting carries and the signs. Multiplication and division are │
|
||||
└─┐ simarily performed. ┌─┘
|
||||
└────────────────────────────────────────────────────────────────────┘*/
|
||||
a=123 /*all of these assignments are identical: */
|
||||
b='123' /*there is no difference in the assignments*/
|
||||
b='123'
|
||||
c='1' || "2" || '3'
|
||||
d= 1 || 2 || 3
|
||||
e= 12 || 3
|
||||
f=120 + 3
|
||||
g=substr(9912388,3,2)
|
||||
g=substr(9912388,3,3)
|
||||
h=left(123456,3)
|
||||
i=right(777.123,3)
|
||||
j=12 + ' 3 '
|
||||
k=0000000123.0000/1 /*divison "normalizes the number (───► 123)*/
|
||||
j=120 + ' 3 '
|
||||
k=0000000123.0000/1 /*division "normalizes the number (──► 123)*/
|
||||
|
||||
/*parsing then, of a decimal number is no */
|
||||
/*parsing of a decimal number is no */
|
||||
/*different then parsing a character string*/
|
||||
/*because decimal numbers ARE character */
|
||||
/*strings. As such, numbers may have */
|
||||
|
|
@ -29,7 +20,7 @@ k=0000000123.0000/1 /*divison "normalizes the number (───► 123)
|
|||
/*leading sign). */
|
||||
|
||||
aa=' 123 ' /*AA's exact value is different the A, */
|
||||
/*but it's numerically equal to A. */
|
||||
/*but it's numerically equal to A. */
|
||||
bb=123. /*the same can be said for the rest of 'em.*/
|
||||
cc=+123
|
||||
dd=' + 123'
|
||||
|
|
@ -67,9 +58,9 @@ cyanF=c2b('copernicium') /*some REXXes support this, others don't. */
|
|||
cyanG=c2d('nilla') /*converts a character string to decimal. */
|
||||
cyanH=d2c(251) /*converts a decimal number to character. */
|
||||
|
||||
cyanI=x2d(fab) /*converts a hexadcimal string to decinal.*/
|
||||
cyanJ=x2c(fab) /*converts a hexadcimal string to chars. */
|
||||
cyanK=x2b(fab) /*converts a hexadcimal string to binary. */
|
||||
cyanI=x2d(fab) /*converts a hexadecimal string to decimal*/
|
||||
cyanJ=x2c(fab) /*converts a hexadecimal string to chars. */
|
||||
cyanK=x2b(fab) /*converts a hexadecimal string to binary.*/
|
||||
|
||||
befog=d2b(144) /*there's no dec──►binary, but see below.*/
|
||||
unfog=b2d(101) /*there's no bin──►decimal, but see below.*/
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue