我试图对两个二进制数进行XOR 例如:
10100010 xor 01000101 = 11100111
matlab的代码:
lloyd = {
"name": "Lloyd",
"homework": [90.0, 97.0, 75.0, 92.0],
"quizzes": [88.0, 40.0, 94.0],
"tests": [75.0, 90.0]
}
alice = {
"name": "Alice",
"homework": [100.0, 97.0, 98.0, 100.0],
"quizzes": [98.0, 99.0, 99.0],
"tests": [100.0, 100.0]
}
tyler = {
"name": "Tyler",
"homework": [0.0, 35.0, 45.0, 22.0],
"quizzes": [0.0, 60.0, 58.0],
"tests": [65.0, 58.0]
}
students = [lloyd,alice,tyler]
def average(numbers):
total= sum(numbers)
total = float(total)
return total / len(numbers)
def get_average(student):
homework= average(student["homework"])
quizzes= average(student["quizzes"])
tests= average(student["tests"])
return 0.1 * homework + 0.3 * quizzes + 0.6 * tests
def get_letter_grade(score):
if score >= 90:
return "A"
elif score >= 80:
return "B"
elif score >= 70:
return "C"
elif score >= 60:
return "D"
else:
return "F"
def get_student_average(gruppo):
for student in gruppo:
results= []
results.append(get_average(student))
print (student["name"])
print (results)
print (get_letter_grade(results))
get_student_average(students)
但是当我使用它时, matlab将这两个数字视为十进制数,并给出小数答案
= 9789327
我怎样才能得到两个二进制数并得到二进制答案?
答案 0 :(得分:4)
问题似乎是MATLAB期望以双重表示形式输入:
不是最优雅,而是一种方法:
{% extends 'admin/model/edit.html' %}
{% from 'admin/lib.html' import extra with context %}
{% from 'admin/lib.html' import form_tag with context %}
{% from 'admin/lib.html' import render_form_fields with context %}
{% macro my_render_form_buttons(cancel_url, extra=None, is_modal=False) %}
<hr>
<div class="form-group">
<div class="col-md-offset-2 col-md-10 submit-row">
<input type="submit" class="btn btn-primary" value="{{ _gettext('Submit') }}" />
{% if extra %}
{{ extra }}
{% endif %}
{% if cancel_url %}
<a href="{{ cancel_url }}" class="btn btn-danger" role="button" {% if is_modal %}data-dismiss="modal"{% endif %}>{{ _gettext('Cancel') }}</a>
{% endif %}
</div>
</div>
{% endmacro %}
{% macro my_render_from(form, cancel_url, extra=None, form_opts=None, action=None, is_modal=False) -%}
{% call form_tag(action=action) %}
{{ render_form_fields(form, form_opts=form_opts) }}
{{ my_render_form_buttons(cancel_url, extra, is_modal) }}
{% endcall %}
{% endmacro %}
{% block edit_form %}
{{ my_render_form(form, return_url, extra(), form_opts) }}
{% endblock %}
或者,将位表示为向量中的元素:
y = dec2bin(bitxor(bin2dec(num2str(10100010)), bin2dec(num2str(01000101))));