當前位置:首頁 » 操作系統 » 源碼計算

源碼計算

發布時間: 2022-02-07 16:25:49

『壹』 計算器源代碼

要什麼樣的
什麼功能的,說清楚好寫

『貳』 一個數的原碼,反碼,補碼怎麼算

計算機中的存儲系統都是用2進制儲存的,對我們輸入的每一個信息它都會自動轉變成二進制的形式,而二進制在存儲的時候就會用到原碼,反碼和補碼例如:輸入25原碼是:0000000000011001反碼: 1111111111100110 補碼: 1111111111100111

數值在計算機中表示形式為機器數,計算機只能識別0和1,使用的是二進制,而在日常生活中人們使用的是十進制,"正如亞里士多德早就指出的那樣,今天十進制的廣泛採用,只不過我們絕大多數人生來具有10個手指頭這個解剖學事實的結果.盡管在歷史上手指計數(5,10進制)的實踐要比二或三進制計數出現的晚. "(摘自<<數學發展史>>有空大家可以看看哦~,很有意思的).為了能方便的與二進制轉換,就使用了十六進制(2 4)和八進制(23).下面進入正題.

數值有正負之分,計算機就用一個數的最高位存放符號(0為正,1為負).這就是機器數的原碼了.假設機器能處理的位數為8.即字長為1byte,原碼能表示數值的范圍為

(-127~-0 +0~127)共256個.

有了數值的表示方法就可以對數進行算術運算.但是很快就發現用帶符號位的原碼進行乘除運算時結果正確,而在加減運算的時候就出現了問題,如下: 假設字長為8bits

( 1 ) 10- ( 1 )10 = ( 1 )10 + ( -1 )10 = ( 0 )10

(00000001)原 + (10000001)原 = (10000010)原 = ( -2 ) 顯然不正確.

因為在兩個整數的加法運算中是沒有問題的,於是就發現問題出現在帶符號位的負數身上,對除符號位外的其餘各位逐位取反就產生了反碼.反碼的取值空間和原碼相同且一一對應. 下面是反碼的減法運算:

( 1 )10 - ( 1 ) 10= ( 1 ) 10+ ( -1 ) 10= ( 0 )10

(00000001) 反+ (11111110)反 = (11111111)反 = ( -0 ) 有問題.

( 1 )10 - ( 2)10 = ( 1 )10 + ( -2 )10 = ( -1 )10

(00000001) 反+ (11111101)反 = (11111110)反 = ( -1 ) 正確

問題出現在(+0)和(-0)上,在人們的計算概念中零是沒有正負之分的.(印度人首先將零作為標記並放入運算之中,包含有零號的印度數學和十進制計數對人類文明的貢獻極大).

於是就引入了補碼概念. 負數的補碼就是對反碼加一,而正數不變,正數的原碼反碼補碼是一樣的.在補碼中用(-128)代替了(-0),所以補碼的表示範圍為:

(-128~0~127)共256個.

注意:(-128)沒有相對應的原碼和反碼, (-128) = (10000000) 補碼的加減運算如下:

( 1 ) 10- ( 1 ) 10= ( 1 )10 + ( -1 )10 = ( 0 )10

(00000001)補 + (11111111)補 = (00000000)補 = ( 0 ) 正確

( 1 ) 10- ( 2) 10= ( 1 )10 + ( -2 )10 = ( -1 )10

(00000001) 補+ (11111110) 補= (11111111)補 = ( -1 ) 正確

所以補碼的設計目的是:

⑴使符號位能與有效值部分一起參加運算,從而簡化運算規則.

⑵使減法運算轉換為加法運算,進一步簡化計算機中運算器的線路設計

所有這些轉換都是在計算機的最底層進行的,而在我們使用的匯編、C等其他高級語言中使用的都是原碼

『叄』 原碼是怎麼算

原碼:在數值前直接加一符號位的表示法。

例如: 符號位=數值位

[+7]原=0 0000111 B

[-7]原=1 0000111 B

注意:a. 數0的原碼有兩種形式:

[+0]原=00000000B [-0]原=10000000B

b. 8位二進制原碼的表示範圍:-127~+127

編碼方式

原碼是有符號數的最簡單的編碼方式,便於輸入輸出,但作為代碼加減運算時較為復雜。

一個字長為n的機器數能表示不同的數字的個數是固定的2^n個,n=8時2^n=256;用來表示有符號數,數的范圍就是 -2^(n-1)-1 ~ 2^(n-1)-1,n=8時,這個范圍就是 -127 ~ +127。

但是在不需要考慮數的正負時,就不需要用一位來表示符號位,n位機器數全部用來表示是數值,這時表示數的范圍就是0~2^n-1,n=8時這個范圍就是0~255。

『肆』 計算機中補碼為10111010,怎麼計算求源碼

源碼→補碼:除符號位外各位取反再+1,那反之,知道補碼求源碼,只需符號位外各位-1再取反嘍。以此題為例,10111010-1=10111001,再取反得11000110,所以源碼即使11000110。

『伍』 計算機源碼,反碼,補碼之間怎麼計算

正數的源碼、反碼、補碼相同
負數的源碼第一位為1,代表負數,反碼為符號位不變,其他為取反,補碼為反碼加1.

『陸』 求計算器源代碼

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace jisuan
{
/// <summary>
/// Form1 的摘要說明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.TextBox textBox2;
private System.Windows.Forms.TextBox textBox3;
private System.Windows.Forms.ComboBox comboBox1;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.Button button3;
/// <summary>
/// 必需的設計器變數。
/// </summary>
private System.ComponentModel.Container components = null;

public Form1()
{
//
// Windows 窗體設計器支持所必需的
//
InitializeComponent();

//
// TODO: 在 InitializeComponent 調用後添加任何構造函數代碼
//
}

/// <summary>
/// 清理所有正在使用的資源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows 窗體設計器生成的代碼
/// <summary>
/// 設計器支持所需的方法 - 不要使用代碼編輯器修改
/// 此方法的內容。
/// </summary>
private void InitializeComponent()
{
this.textBox1 = new System.Windows.Forms.TextBox();
this.textBox2 = new System.Windows.Forms.TextBox();
this.textBox3 = new System.Windows.Forms.TextBox();
this.comboBox1 = new System.Windows.Forms.ComboBox();
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.button3 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(24, 72);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(100, 21);
this.textBox1.TabIndex = 0;
this.textBox1.TextChanged += new System.EventHandler(this.textBox1_TextChanged);
//
// textBox2
//
this.textBox2.Location = new System.Drawing.Point(312, 72);
this.textBox2.Name = "textBox2";
this.textBox2.Size = new System.Drawing.Size(100, 21);
this.textBox2.TabIndex = 1;
//
// textBox3
//
this.textBox3.Location = new System.Drawing.Point(448, 72);
this.textBox3.Name = "textBox3";
this.textBox3.Size = new System.Drawing.Size(88, 21);
this.textBox3.TabIndex = 2;
//
// comboBox1
//
this.comboBox1.Items.AddRange(new object[] {
"+",
"-",
"*",
"/"});
this.comboBox1.Location = new System.Drawing.Point(152, 72);
this.comboBox1.Name = "comboBox1";
this.comboBox1.Size = new System.Drawing.Size(121, 20);
this.comboBox1.TabIndex = 3;
this.comboBox1.SelectedIndexChanged += new System.EventHandler(this.comboBox1_SelectedIndexChanged);
//
// button1
//
this.button1.Location = new System.Drawing.Point(64, 184);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(104, 32);
this.button1.TabIndex = 4;
this.button1.Text = "計算";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// button2
//
this.button2.Location = new System.Drawing.Point(216, 192);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(75, 23);
this.button2.TabIndex = 5;
this.button2.Text = "清除";
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// button3
//
this.button3.Location = new System.Drawing.Point(376, 192);
this.button3.Name = "button3";
this.button3.Size = new System.Drawing.Size(75, 23);
this.button3.TabIndex = 6;
this.button3.Text = "退出";
this.button3.Click += new System.EventHandler(this.button3_Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(656, 366);
this.Controls.Add(this.button3);
this.Controls.Add(this.button2);
this.Controls.Add(this.button1);
this.Controls.Add(this.comboBox1);
this.Controls.Add(this.textBox3);
this.Controls.Add(this.textBox2);
this.Controls.Add(this.textBox1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);
this.PerformLayout();

}
#endregion

/// <summary>
/// 應用程序的主入口點。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
public double jia(double a,double b)
{
return a+b;
}
public double jian(double a,double b)
{
return a-b;
}
public double cheng(double a,double b)
{
return a*b;
}
public double chu(double a,double b)
{
return a/b;
}

private void comboBox1_SelectedIndexChanged(object sender, System.EventArgs e)
{

}

private void textBox1_TextChanged(object sender, System.EventArgs e)
{

}

private void button1_Click(object sender, System.EventArgs e)
{
string i=this.comboBox1.SelectedItem.ToString();

switch(i)
{

case "+":this.textBox3.Text=this.jia(double.Parse(this.textBox1.Text),double.Parse(this.textBox2.Text)).ToString();

break;

case "-":this.textBox3.Text=this.jian(double.Parse(this.textBox1.Text),double.Parse(this.textBox2.Text)).ToString();
break;
case "*":this.textBox3.Text=this.cheng(double.Parse(this.textBox1.Text),double.Parse(this.textBox2.Text)).ToString();
break;
case"/" :this.textBox3.Text=this.chu(double.Parse(this.textBox1.Text),double.Parse(this.textBox2.Text)).ToString();
break;
}

}

private void button2_Click(object sender, System.EventArgs e)
{
this.textBox1.Text=null;
this.textBox2.Text=null;
this.textBox3.Text = null;
}

private void button3_Click(object sender, EventArgs e)
{

//this.Hide();
Application.Exit();
//this.Close();

}
}
}
是否可以解決您的問題?

『柒』 計算java源代碼

public class Q1{
public static void main(String args[]){
int a=5;
int b=6;
int m=a*b;
System.out.println(m);
}

}

需要main 方法的

『捌』 計算器的C++源代碼

#include <iostream>
#include <cstdio>

using namespace std;
class jishu
{
public:
jishu();

double a(char );
void b(int,int );

private:

double c;
double e;
char f;
};
jishu::jishu()
{
cout<<"計算器小程序加(+)、減(-)、乘(*)、除(/)"<<endl;
}
double jishu::a(char k)
{
switch (k)
{
case '*':
return c*e;
break;
case '/':
return c/e;
break;
case '+':
return c+e;
break;
case '-':
return c-e;
break;

default:
cout<<"輸入錯誤,請重新輸入"<<endl;
while(getchar() != '\n'); //加了1個C格式的清除緩沖區語句

}
}

void jishu::b(int h,int w)
{
c=h;
e=w;

}
void main()
{

jishu ffff;
while(int k=1)
{

double p,m,w; char o;
cin>>p;

cin>>o;
cin>>m;
cout<<"答案是:";

ffff.b(p,m);
ffff.a(o);
w=ffff.a(o);
cout<<p<<o<<m<<"="<<w<<endl;

『玖』 如何查看電腦上某程序的源代碼 如計算器

可以通過GitHub源代碼ping在計算機中檢查計算器的源代碼。具體操作方式如下:

1、進入GitHub的Microsoft個人問題主頁,如下圖所示。

(9)源碼計算擴展閱讀:

GitHub的Windows應用

GitHub 使用 git 分布式版本控制系統,而 git 最初是 LinusTorvalds 為幫助Linux開發而創造的,它針對的是 Linux 平台,因此 git 和 Windows 從來不是最好的朋友,因為它一點也不像Windows。

GitHub 發布了GitHub for Windows,為 Windows 平台開發者提供了一個易於使用的 Git 圖形客戶端。

GitHub forWindows是一個 Metro 風格應用程序,集成了自包含版本的 Git,bash 命令行 shell,PowerShell 的 posh-git 擴展。

GitHub 為 Windows 用戶提供了一個基本的圖形前端去處理大部分常用版本控制任務,可以創建版本庫,向本地版本庫遞交補丁,在本地和遠程版本庫之間同步。微軟也通過CodePlex向開發者提供 git 版本控制系統,而 GitHub 創造了一個更具有吸引力的 Windows 版本。

『拾』 知道 補碼,如何 計算 原碼

兩種計算方法:

演算法1: 補碼=原碼取反再加1的逆運算
10010110是補碼,應先減去1變為反碼,得10010101;
由反碼取得源碼即除符號位外其他為按位取反,得11101010,即十進制數的-106

演算法2:負數補碼速演算法,由最低位(右)向高位(左)查找到第一個1與符號位之間的所有數字按位取反的逆運算
10010110是補碼,符號位與最後一個1之間的所有數字按位取反,得11101010

兩種演算法得出同樣結果

熱點內容
p搜系統只緩存1頁為什麼 發布:2024-09-20 16:48:51 瀏覽:838
上網的賬號和密碼是什麼東西 發布:2024-09-20 16:31:31 瀏覽:612
安卓手機王者榮耀如何調超高視距 發布:2024-09-20 16:31:30 瀏覽:428
安卓G是什麼app 發布:2024-09-20 16:23:09 瀏覽:81
iphone怎麼壓縮文件 發布:2024-09-20 16:08:18 瀏覽:356
linux查看用戶名密碼是什麼 發布:2024-09-20 16:03:20 瀏覽:744
mac執行python腳本 發布:2024-09-20 15:58:52 瀏覽:779
單片機android 發布:2024-09-20 09:07:24 瀏覽:765
如何提高三星a7安卓版本 發布:2024-09-20 08:42:35 瀏覽:664
如何更換伺服器網站 發布:2024-09-20 08:42:34 瀏覽:311