Ruby中的位移 [英] Bit shifting in Ruby

查看:101
本文介绍了Ruby中的位移的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在将Visual Basic应用程序转换为Ruby,因为我们正在将其移至Web.但是,在转换某些算法时,我遇到了有关移位的问题.

I'm currently converting a Visual Basic application to Ruby because we're moving it to the web. However when converting some algorithms I've run into a problem concerning bit shifting.

据我所知,问题在于VB对Integer类型执行的大小掩码(如

How I understand it, the problem lies in the size mask VB enforces on Integer types (as explained Here). Ruby, in practice, doesn't differentiate in these types.

那么问题是

Dim i As Integer = 182
WriteLine(i << 24) '-1241513984

Ruby

puts 182 << 24 # 3053453312

我一直在Google上搜索并阅读了过去几个小时的移位信息,但是还没有找到解决此问题的方法或方向.

I've been Googling and reading up on bit shifting the last hours but haven't found a way, or direction even, to tackle this problem.

推荐答案

您需要复制Visual Basic正在做什么,即

You need to replicate what visual basic is doing, namely

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