你如何写在Ruby中的二进制文字 [英] How do you write a binary literal in ruby?

查看:256
本文介绍了你如何写在Ruby中的二进制文字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大多数语言(包括红宝石)允许写入至少在三个基地一些文字:十进制,八和十六进制。在十进制的数字是平常的事情,并写(大多数)人自然写号,96写成 96 。由零pfixed数字$ P $是PTED为八进制通常跨$ P $为主:96将被写成 0140 。基于十六进制数字通常是美元的 0X pfixed p $ 96就可以写成 0x60的

Most languages (Ruby included) allow number literals to be written in at least three bases: decimal, octal and hexadecimal. Numbers in decimal base is the usual thing and are written as (most) people naturally write numbers, 96 is written as 96. Numbers prefixed by a zero are usually interpreted as octal based: 96 would be written as 0140. Hexadecimal based numbers are usually prefixed by 0x: 96 would be written as 0x60.

现在的问题是:我可以写号为Ruby的二进制文字?怎么样?

The question is: can I write numbers as binary literals in Ruby? How?

推荐答案

使用0B preFIX

use 0b prefix

>> 0b100
=> 4

这篇关于你如何写在Ruby中的二进制文字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆