September 2017 Update
This commit is contained in:
parent
bba7bfd280
commit
ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions
|
|
@ -0,0 +1,6 @@
|
|||
# Version 5.2
|
||||
txt = "100"
|
||||
for base = 2:21
|
||||
base10 = parse(Int, txt, base)
|
||||
println("String $txt in base $base is $base10 in base 10")
|
||||
end
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
@show parse(Int, "123459")
|
||||
@show parse(Int, "0xabcf123")
|
||||
@show parse(Int, "0o7651")
|
||||
@show parse(Int, "0b101011001")
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
// version 1.1.2
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
val s = "100"
|
||||
val bases = intArrayOf(2, 8, 10, 16, 19, 36)
|
||||
for (base in bases)
|
||||
println("$s in base ${"%2d".format(base)} is ${s.toInt(base)}")
|
||||
}
|
||||
|
|
@ -0,0 +1,79 @@
|
|||
function Select-NumberFromString
|
||||
{
|
||||
[CmdletBinding(DefaultParameterSetName="Decimal")]
|
||||
[OutputType([PSCustomObject])]
|
||||
Param
|
||||
(
|
||||
[Parameter(Mandatory=$true,
|
||||
ValueFromPipeline=$true,
|
||||
ValueFromPipelineByPropertyName=$true,
|
||||
Position=0)]
|
||||
[string]
|
||||
$InputObject,
|
||||
|
||||
[Parameter(ParameterSetName="Decimal")]
|
||||
[Alias("d","Dec")]
|
||||
[switch]
|
||||
$Decimal,
|
||||
|
||||
[Parameter(ParameterSetName="Hexadecimal")]
|
||||
[Alias("h","Hex")]
|
||||
[switch]
|
||||
$Hexadecimal,
|
||||
|
||||
[Parameter(ParameterSetName="Octal")]
|
||||
[Alias("o","Oct")]
|
||||
[switch]
|
||||
$Octal,
|
||||
|
||||
[Parameter(ParameterSetName="Binary")]
|
||||
[Alias("b","Bin")]
|
||||
[switch]
|
||||
$Binary
|
||||
)
|
||||
|
||||
Begin
|
||||
{
|
||||
switch ($PSCmdlet.ParameterSetName)
|
||||
{
|
||||
"Decimal" {$base = 10; $pattern = '[+-]?\b[0-9]+\b'; break}
|
||||
"Hexadecimal" {$base = 16; $pattern = '\b[0-9A-F]+\b' ; break}
|
||||
"Octal" {$base = 8; $pattern = '\b[0-7]+\b' ; break}
|
||||
"Binary" {$base = 2; $pattern = '\b[01]+\b' ; break}
|
||||
"Default" {$base = 10; $pattern = '[+-]?\b[0-9]+\b'; break}
|
||||
}
|
||||
}
|
||||
Process
|
||||
{
|
||||
foreach ($object in $InputObject)
|
||||
{
|
||||
if ($object -match $pattern)
|
||||
{
|
||||
$string = $Matches[0]
|
||||
}
|
||||
else
|
||||
{
|
||||
$string = $null
|
||||
}
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
$value = [Convert]::ToInt32($string, $base)
|
||||
}
|
||||
catch
|
||||
{
|
||||
$value = $null
|
||||
}
|
||||
|
||||
[PSCustomObject]@{
|
||||
Number = $value
|
||||
String = $string
|
||||
Base = $base
|
||||
IsNumber = $value -is [int]
|
||||
InputString = $object
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
$file = @'
|
||||
John Doe abc1 K2hdystkrs
|
||||
Jane Doe xyz2 Ew3jtdkufy
|
||||
Joe Blow def3 Ouy1ttluyl
|
||||
'@ -split [Environment]::NewLine
|
||||
|
||||
$file | Select-NumberFromString -Hexadecimal | Format-Table
|
||||
|
|
@ -25,7 +25,7 @@ bb=123. /*the same can be said for the rest of 'em.*/
|
|||
cc=+123
|
||||
dd=' + 123'
|
||||
ee=0000123
|
||||
ff=1.23e+1
|
||||
ff=1.23e+2
|
||||
gg=001.23E0002
|
||||
hh=1230e-1
|
||||
ii=122.999999999999999999999999999999999 /*assuming NUMERIC DIGITS 9 */
|
||||
|
|
|
|||
|
|
@ -0,0 +1,6 @@
|
|||
fcn b2b(base){
|
||||
ns:=[20..30].pump(List,T("toString",base));
|
||||
ns.println();
|
||||
ns.pump(List,T("toInt",base)).println("\n")
|
||||
}
|
||||
b2b(2); b2b(10); b2b(16); b2b(19);
|
||||
Loading…
Add table
Add a link
Reference in a new issue