如何在python中使用XOR进行二进制操作?(How do binary operations with XOR in python work?)
我在python中的xor运算符(
^
)有以下问题。 我有两个二进制数,设a = 10100111
和b = 10000000
。 当我使用xor运算符时,print (10000000 ^ 10100111)
我得到的结果是166671而不是00100111.但是,当我使用时
print (100 ^ 101)
我得到了二进制1(001)的适当结果。 即使我使用
print int(a) ^ int(b)
我仍然得到166671的结果。
问题:
为什么我得到166671的结果而不是00100111的二进制结果?
当我使用100 ^ 101时,为什么会得到适当的结果?
我正在运行Python 2.7.2版。
I have the following problem with the xor operator (
^
) in python. I have two binary numbers, leta = 10100111
andb = 10000000
. When I use the xor operator,print (10000000 ^ 10100111)
I get the result of 166671 instead of 00100111. However, when I use
print (100 ^ 101)
I get the appropriate result in binary of 1 (001). Even if I use
print int(a) ^ int(b)
I still get the result of 166671.
Questions:
Why do I get the result of 166671 instead of the binary result of 00100111?
Why do I get the appropriate result when I use 100^101?
I am running Python version 2.7.2.
原文:https://stackoverflow.com/questions/19252626
最满意答案
解决了安装SSH客户端和服务器后设置安全密钥的问题。 可用于诊断SSH问题的实用程序是https://github.com/capistrano-plugins/capistrano-ssh-doctor感谢创建者! 干杯。
Resolved the problem after installing SSH client and server, setting up security keys. Great utility, which can be used to diagnose SSH problems is https://github.com/capistrano-plugins/capistrano-ssh-doctor thanks for creator! Cheers.
相关问答
更多-
使用Capistrano通过SSH连接到Bitbucket时出错(Error connecting via SSH to Bitbucket using Capistrano)[2022-09-04]
Capistrano尝试在部署目标 (即VPS) 处签出git存储库。 因此,您需要从VPS计算机获得与bitbucket的ssh连接。 我猜你的本地主机和VPS的ssh身份不同,而且你只在bitbucket中配置了本地机器的ssh密钥。 你可以在本地机器上比较~/.ssh/id_rsa.pub ,并在VPS上作为developer登录吗? 如果密钥不同,则需要将公共ssh密钥( id_rsa.pub文件)从VPS添加到bitbucket配置,以便您可以使用ssh从VPS连接到bitbucket。 Capi ... -
我不得不说我不确定,因为我没有能力测试,但这应该是有效的: cap deploy:cleanup -s keep_releases=0 因为它从服务器上擦除每个版本(缓存)。 显然,您还需要删除shared/cached-copy ,因为根据以下注释,上述Capistrano调用似乎没有被清除。 I gotta say I’m not sure, since I haven’t been able to test this but this should work: cap deploy:cleanup ...
-
默认情况下,Capistrano使用SSH代理转发。 实际上,这意味着它将使用您的本地SSH密钥与BitBucket进行身份验证。 也许您的本地密钥已更改或不再具有BitBucket访问权限,这可以解释为什么部署不再有效。 您可以禁用Capistrano的SSH代理转发(从而允许Git使用您在服务器上安装的部署密钥),如下所示: set :ssh_options, { forward_agent: false } By default, Capistrano uses SSH agent forwardi ...
-
这可能是一个很好的起点: namespace :solr do task :reindex do run "cd #{current_path} && #{rake} RAILS_ENV=#{rails_env} sunspot:solr:reindex" end end 你可以调用rake sunspot:solr:stop而不是杀死? 如果你打算重新索引,我不 ...
-
这通常表示SSH密钥问题。 确保与BitBucket关联的~/.ssh/id_(dsa|rsa)位于~/.ssh/id_(dsa|rsa)并且是chmod 600。 This usually indicates an SSH key issue. Make sure that the private key which you have associated with BitBucket is in ~/.ssh/id_(dsa|rsa) and is chmod 600.
-
我在这种情况下所做的是使用两个Capistrano部署和一些符号链接。 为了这个答案,让我们将$REPO1HOME定义$REPO1HOME的位置。 首先,我将Repo2中的文件名添加为Repo1(config / deploy.rb)中的shared_file: set :shared_files, 'app/Extensions/TaskOneExtension.php' 此时,当您部署Repo1时,将从$REPO1HOME/releases/[timestamp]/app/Extensions/Tas ...
-
我终于找到了,所以我将在这里发布解决方案:在PC上,你需要安装Putty并用你的id_rsa键启动Pageant。 就是这样! I finally found so I will post the solution here: On PC, you need to install Putty and launch Pageant with your id_rsa key inside. And that's it!
-
解决了安装SSH客户端和服务器后设置安全密钥的问题。 可用于诊断SSH问题的实用程序是https://github.com/capistrano-plugins/capistrano-ssh-doctor感谢创建者! 干杯。 Resolved the problem after installing SSH client and server, setting up security keys. Great utility, which can be used to diagnose SSH problem ...
-
负责定义要部署的目录的参数是:deploy_to 。 因此,为了将Capistrano部署到/var/www/html/web_app/您需要相应地配置它。 在下面set :keep_releases, 2将:deploy_to参数设置为/var/www/html/web_app/ 。 你的deploy.rb文件如下所示: set :application, "hunter" set :repo_url, "git@bitbucket.org:*****.git" # Default value for k ...
-
不要使用https存储库路径总是使用git路径,并将ssh密钥添加到服务器。 Don't use https repository path always use git path for this and add your ssh key to your server.