Skip to Content
For Enterprise
For Government
For Higher Ed
For Individuals
For Marketing
For Enterprise
For Government
For Higher Ed
For Individuals
For Marketing
Explore Skills
Cloud Computing
Microsoft Azure
Amazon Web Services (AWS)
Google Cloud
Cloud Migration
Cloud Deployment
Cloud Platforms
Data Engineering
Data Warehouse
SQL
Apache Spark
Microsoft SQL Server
MySQL
Kafka
Data Lake
Streaming & Messaging
NoSQL Databases
Relational Databases
Data Science
Pandas
R
MATLAB
SAS
D3
Power BI
Tableau
Statistics
Exploratory Data Analysis
Data Visualization
AI & ML
Generative AI
Machine Learning
Artificial Intelligence (AI)
Deep Learning
Reinforcement Learning
Natural Language Processing
TensorFlow
Scikit-Learn
Hyperparameter Tuning
MLOps
Programming Languages
Java
JavaScript
Spring
Python
Go
C#
C++
C
Swift
Rust
Functional Programming
Software Architecture
Object-Oriented
Distributed Systems
Domain-Driven Design
Architectural Patterns
IT/Ops
Kubernetes
Docker
GitHub
Terraform
Continuous Delivery
Continuous Integration
Database Administration
Computer Networking
Operating Systems
IT Certifications
Security
Network Security
Application Security
Incident Response
Zero Trust Model
Disaster Recovery
Penetration Testing / Ethical Hacking
Governance
Malware
Security Architecture
Security Engineering
Security Certifications
Design
Web Design
Graphic Design
Interaction Design
Film & Video
User Experience (UX)
Design Process
Design Tools
Business
Agile
Project Management
Product Management
Marketing
Human Resources
Finance
Team Management
Business Strategy
Digital Transformation
Organizational Leadership
Soft Skills
Professional Communication
Emotional Intelligence
Presentation Skills
Innovation
Critical Thinking
Public Speaking
Collaboration
Personal Productivity
Confidence / Motivation
Features
All features
Verifiable skills
AI Academy
Courses
Certifications
Interactive learning
Live events
Superstreams
Answers
Insights reporting
Radar Blog
Buy Courses
Plans
Sign In
Try Now
O'Reilly Platform
book
量子计算机编程:从入门到实践
by
Eric R. Johnston
,
Nicholas Harrigan
,
Mercedes Gimeno-Segovia
July 2021
Beginner to intermediate
274 pages
7h 10m
Chinese
Posts & Telecom Press
Content preview from
量子计算机编程:从入门到实践
量子算术与逻辑
|
77
准备
准备
图
5-8
:
+=
运算
示例代码
请在
http://oreilly-qc.github.io?p=5-2
上运行本示例。
示例
5-2
两个量子整数相加
// a += b
a
.
add
(
b
);
与图
5-3
所示的情况一样,图
5-8
中的准备步骤只用来提供测试输入,并不是运算的一部
分。同理,以相反的顺序运行
a += b
的运算门,就可以实现
a –= b
。
5.4
负整数
到目前为止,我们只讨论了正整数的加减运算。如何在
QPU
寄存器中表示和操作负整数
呢?答案是采用
二进制补码
(
two
’
s-complement
),就像所有现代
CPU
和编程语言所使用
的那样。接下来快速回顾二进制补码的相关知识,并特别考虑量子比特。
对于给定的位数,只需将一半的值与负数关联,同时将另一半的值与正数关联。例如,可
以用
3
位的寄存器表示整数
–4
、
–3
、
–2
、
–1
、
0
、
1
、
2
、
3
,如表
5-1
所示。
表
5-1
:二进制补码表示
0
1
2
3
–
4
–
3
–
2
–
1
000
001
010
011
100
101
110
111
如果你从未遇到过二进制补码,那么可能不太理解负数和二进制值之间的关系。不过,这
种特殊的选择有一个令人惊讶的好处,即适用于正整数的基本算术方法也可以直接用于二
进制补码。我们还可以从表
5-1
中看出,最高位能够有效地指示这些数的正负。
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.
Start your free trial
You might also like
JAVASCRIPT之美|聽頂尖程式設計師闡述他們的思維
Anton Kovalyov
Go程序设计语言
艾伦A. A.多诺万, 布莱恩W. 柯尼汉
C++语言导学(原书第2版)
本贾尼 斯特劳斯特鲁普
监控运维实践:原则与策略
Mike Julian
Publisher Resources
ISBN: 9787115566355