Skip to Content
Raku学习手册
book

Raku学习手册

by brian d foy
October 2020
Beginner to intermediate
499 pages
9h 13m
Chinese
China Electric Power Press Ltd.
Content preview from Raku学习手册
猜数
39
在基数(基数用十进制表示)前加一个冒号,然后把数字放在尖括号里:
:7<254>
:19<IG88>
:26<HAL9000>
:36<THX1138>
练习
2.5
REPL
中尝试这些不常见的基数例子。相应的十进制数是什么?
格式化数字
字面数都是对象。可以在对象上调用方法。
.base
方法允许你指定想要表示哪种进制:
put 0x89.base: 10; # 137
还可以选择其他进制,最多可以到三十六进制:
put 0x89.base: 2; # 10001001
put 0x89.base: 8; # 211
put 0x89.base: 16; # 89
练习
2.6
写一个程序,接受一个十进制数作为唯一的命令行参数。输出它的二进制、八
进制、十进制和十六进制值。如果在命令行上提供一个十六进制数会发生什么?
如果用东阿拉伯数字指定十进制数呢?
在前面的练习中,不能指定一个十六进制数作为实参。这是因为,实际上你并不是
指定一个数作为参数,它是由数字字符组成的文本。如果你想使用十六进制数,必
须告诉程序如何转换这个数,为此可以使
.parse-base
你要告诉它你想使用哪一
个进制,它会完成其余的工作:
my $number = $thingy.parse-base: 16;
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

可编程网络自动化

可编程网络自动化

Jason Edelman, Scott S. Lowe, Matt Oswalt
程序员学数据结构

程序员学数据结构

Posts & Telecom Press, William Smith
R深度学习权威指南

R深度学习权威指南

Posts & Telecom Press, Joshua F. Wiley
AI工程

AI工程

Chip Huyen

Publisher Resources

ISBN: 9787519848002