从0开始<六>:位运算符相关

本文介绍了三个位操作函数:getbits用于获取指定位置的位值;setbits用于设置指定位置的位值;invert用于求反指定位置的位值。通过具体的C语言实现展示了这些操作,并提供了一个测试程序。

程序一:编写一个函数getbits(x,p,n),它将返回x中从右边数第p位开始向右边n位的字段,这里假定右边第一位是第0位,n和 p都是合理的正值

先看程序:(先把指定为移到最右边,然后再与1与,即取出来即可)

unsigned getbits(unsigned x, int p, int n)
{
	return (x >> (p+1-n)) & ~( ~0 << n);
}
问题一:什么叫n和p都为合理的正值 

答:即:p首先得在 unsigned 的范围内p+1-n>=0;

问题二:unsigned是什么类型

答:点击打开链接

程序二:编写一个函数setbits(x,p,n,y),该函数返回对x执行下列操作后的结果值:将x中从第p位开始的n个(二进制)位设置为y中最右边n位的值,x中的其余各位保持不变

解释:先看后部分吧,后面的就是先取出y的最右边n位值,然后移动到p~(p+1-n)这个范围来,取出来的值,除了这个范围是与 y之前的相同外,其他的都是 0.

前面的就是把p~(p+1-n)这个范围都变为0就好,其他位不变,具体操作方法看程序就好,个人觉得这个每个人变换的方法不同。

unsigned setbits(unsigned x, int p, int n, unsigned y)
{
	return (x & ((~0 << (p + 1)) | (~(~0 << (p + 1 - n))))) | ((y & ~(~0 << n)) << (p + 1 - n));
}

int main(void)
{
  unsigned i;
  unsigned j;
  unsigned k;
  int p;
  int n;
  
  for(i = 0; i < 30000; i += 511)
  {
    for(j = 0; j < 1000; j += 37)
    {
      for(p = 0; p < 16; p++)
      {
        for(n = 1; n <= p + 1; n++)
        {
          k = setbits(i, p, n, j);
          printf("setbits(%u, %d, %d, %u) = %u\n", i, p, n, j, k);
        }
      }
    }
  }
  return 0;
} 
问题一:测试程序有些奇怪

答:的确是,哈哈,我也不知道为啥。


程序三:编写一个函数invert(x,p,n),该函数返回对x执行下列操作后的结果值:将x中从第p为开始的n个(二进制)为求反(即,1变0,0变成1),x的其余各位保持不变。

思路:把需要改变的那部分与 1异或即可。

unsigned invert(unsigned x, int p, int n)
{
    return x ^ (~(~0U << n) << p);
}

#include <stdio.h>

int main(void)
{
  unsigned x;
  int p, n;

  for(x = 0; x < 700; x += 49)
    for(n = 1; n < 8; n++)
      for(p = 1; p < 8; p++)
        printf("%u, %d, %d: %u\n", x, n, p, invert(x, n, p));
  return 0;
} 

1.利用运符友元重载技术实现Clock类的时间计和输入和输出技术,其Clock类的基本程序代码如下: #include<iostream> #include<string> using namespace std; class Clock { private: int hour; //小时 int min; //分钟 int sec; //秒 string weekday; //星期 public: // 构造函数 Clock(int h = 0, int m = 0, int s = 0, string wd = "星期一") : hour(h), min(m), sec(s), weekday(wd) {} // 友元函数声明 friend ostream& operator<<(ostream& out, const Clock& c); friend istream& operator>>(istream& in, Clock& c); friend Clock operator+(const Clock& c1, const Clock& c2); //运结果的星期取c1的星期 friend Clock operator-(const Clock& c1, const Clock& c2); //运结果的星期取c1的星期 // 辅助函数:时间规范化 void normalize() { if (sec >= 60) { min += sec / 60; sec %= 60; } else if (sec < 0) { int borrow = (-sec + 59) / 60; min -= borrow; sec += borrow * 60; } if (min >= 60) { hour += min / 60; min %= 60; } else if (min < 0) { int borrow = (-min + 59) / 60; hour -= borrow; min += borrow * 60; } if (hour >= 24) { hour %= 24; } else if (hour < 0) { hour = (hour % 24 + 24) % 24; } } }; int main() { // 测试默认构造函数 Clock c1(14, 30, 45, "星期一"); cout << "Clock c1: " << c1 << endl; // 测试输入 Clock c2; // cin >> c2; // 取消注释可以进行手动输入测试 c2 = Clock(2, 45, 20, "星期二"); cout << "Clock c2: " << c2 << endl; // 测试加法 Clock c3 = c1 + c2; cout << "c1 + c2 = " << c3 << endl; // 测试减法 Clock c4 = c1 - c2; cout << "c1 - c2 = " << c4 << endl; // 测试时间规范化(进) Clock c5(23, 59, 59, "星期五"); Clock c6(0, 0, 2, "星期"); Clock c7 = c5 + c6; cout << "23:59:59 + 2 seconds = " << c7 << endl; // 测试时间规范化(借) Clock c8(1, 0, 0, "星期天"); Clock c9(0, 1, 30, "星期一"); Clock c10 = c8 - c9; cout << "01:00:00 - 00:01:30 = " << c10 << endl; return 0; }
01-04
package com.example.calculator; import android.graphics.Color; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.TextView; import androidx.appcompat.app.AppCompatActivity; public class MainActivity extends AppCompatActivity { // 记忆功能变量 private TextView tv_mc,tv_mr; private double memoryValue = 0; // UI组件 private TextView displayTextView; private TextView expressionTextView; // 计器状态变量 private double previousValue = 0; private String pendingOperator = ""; private boolean isNewNumber = true; private boolean resetOnNextInput = false; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); initializeViews(); setupButtonClickListeners(); } private void initializeViews() { displayTextView = findViewById(R.id.editText); expressionTextView = findViewById(R.id.editText_1); tv_mc=findViewById(R.id.tv_mc); tv_mr=findViewById(R.id.tv_mr); updateDisplay("0"); } private void setupButtonClickListeners() { // 数字按钮 findViewById(R.id.btn_num_0).setOnClickListener(v -> onNumberClick("0")); findViewById(R.id.btn_num_1).setOnClickListener(v -> onNumberClick("1")); findViewById(R.id.btn_num_2).setOnClickListener(v -> onNumberClick("2")); findViewById(R.id.btn_num_3).setOnClickListener(v -> onNumberClick("3")); findViewById(R.id.btn_num_4).setOnClickListener(v -> onNumberClick("4")); findViewById(R.id.btn_num_5).setOnClickListener(v -> onNumberClick("5")); findViewById(R.id.btn_num_6).setOnClickListener(v -> onNumberClick("6")); findViewById(R.id.btn_num_7).setOnClickListener(v -> onNumberClick("7")); findViewById(R.id.btn_num_8).setOnClickListener(v -> onNumberClick("8")); findViewById(R.id.btn_num_9).setOnClickListener(v -> onNumberClick("9")); // 小数点按钮 findViewById(R.id.btn_num_dot).setOnClickListener(v -> onDecimalClick()); // 运符按钮 findViewById(R.id.btn_symbol_plus).setOnClickListener(v -> onOperatorClick("+")); findViewById(R.id.btn_symbol_minus).setOnClickListener(v -> onOperatorClick("-")); findViewById(R.id.btn_symbol_multiply).setOnClickListener(v -> onOperatorClick("×")); findViewById(R.id.btn_symbol_divide).setOnClickListener(v -> onOperatorClick("÷")); findViewById(R.id.btn_symbol_equals).setOnClickListener(v -> onEqualsClick()); // 功能按钮 findViewById(R.id.btn_clear).setOnClickListener(v -> onClearClick()); findViewById(R.id.btn_clear_entry).setOnClickListener(v -> onClearEntryClick()); findViewById(R.id.btn_clear_image).setOnClickListener(v -> onBackspaceClick()); findViewById(R.id.btn_symbol_plus_minus).setOnClickListener(v -> onPlusMinusClick()); findViewById(R.id.btn_symbol_percent).setOnClickListener(v -> onPercentClick()); // 科学计按钮 findViewById(R.id.btn_symbol_square_root).setOnClickListener(v -> onSqrtClick()); findViewById(R.id.btn_symbol_square).setOnClickListener(v -> onSquareClick()); findViewById(R.id.btn_symbol_x_inverse).setOnClickListener(v -> onReciprocalClick()); // 记忆功能按钮 findViewById(R.id.tv_mc).setOnClickListener(v -> onMemoryClearClick()); findViewById(R.id.tv_mr).setOnClickListener(v -> onMemoryRecallClick()); findViewById(R.id.tv_m_plus).setOnClickListener(v -> onMemoryAddClick()); findViewById(R.id.tv_m_minus).setOnClickListener(v -> onMemorySubtractClick()); findViewById(R.id.tv_ms).setOnClickListener(v -> onMemoryStoreClick()); } /** * 处理数字按钮点击事件 * * @param number 按下的数字 */ private void onNumberClick(String number) { if (resetOnNextInput) { resetCalculator(); } String currentDisplay = displayTextView.getText().toString(); String digitsOnly = currentDisplay.replace(".", "").replace("-", ""); if (digitsOnly.length() >= 9 && !isNewNumber) { return; } if (isNewNumber) { updateDisplay(number); isNewNumber = false; } else { if (currentDisplay.equals("0")) { updateDisplay(number); } else { updateDisplay(currentDisplay + number); } } } /** * 处理小数点按钮点击事件 */ private void onDecimalClick() { if (resetOnNextInput) { resetCalculator(); } String currentDisplay = displayTextView.getText().toString(); if (isNewNumber) { updateDisplay("0."); isNewNumber = false; } else if (!currentDisplay.contains(".")) { updateDisplay(currentDisplay + "."); } } /** * 处理运符按钮点击事件 * * @param operator 运符 (+, -, ×, ÷) */ private void onOperatorClick(String operator) { String currentDisplay = displayTextView.getText().toString(); // 格式化当前显示的数字,去除不必要的小数点和零 double currentValue = Double.parseDouble(currentDisplay); String formattedValue = formatResult(currentValue); if (!pendingOperator.isEmpty()) { // 如果已有待处理的运符,先计之前的表达式 onEqualsClick(); formattedValue = formatResult(Double.parseDouble(displayTextView.getText().toString())); } else { previousValue = currentValue; } pendingOperator = operator; isNewNumber = true; resetOnNextInput = false; // 更新表达式显示,使用格式化后的数值 expressionTextView.setText(formattedValue + " " + operator); } /** * 处理等号按钮点击事件 */ private void onEqualsClick() { if (pendingOperator.isEmpty()) return; String currentDisplay = displayTextView.getText().toString(); double currentValue = Double.parseDouble(currentDisplay); // 格式化当前显示的数值 String formattedCurrentValue = formatResult(currentValue); double result = 0; try { switch (pendingOperator) { case "+": result = previousValue + currentValue; break; case "-": result = previousValue - currentValue; break; case "×": result = previousValue * currentValue; break; case "÷": if (currentValue == 0) { // 处理除零错误 updateDisplay("除数不能为0"); expressionTextView.setText(""); resetCalculator(); return; } result = previousValue / currentValue; break; } // 格式化结果 String resultStr = formatResult(result); updateDisplay(resultStr); // 更新表达式显示,使用格式化后的数值 String formattedPreviousValue = formatResult(previousValue); expressionTextView.setText(formattedPreviousValue + " " + pendingOperator + " " + formattedCurrentValue + " ="); // 重置状态 previousValue = result; pendingOperator = ""; isNewNumber = true; resetOnNextInput = true; } catch (Exception e) { updateDisplay("错误"); expressionTextView.setText(""); resetCalculator(); } } /** * 处理清除按钮点击事件(清除所有) */ private void onClearClick() { resetCalculator(); updateDisplay("0"); expressionTextView.setText(""); } /** * 处理清除条目按钮点击事件(仅清除当前输入) */ private void onClearEntryClick() { updateDisplay("0"); isNewNumber = true; } /** * 处理退格按钮点击事件 */ private void onBackspaceClick() { String currentDisplay = displayTextView.getText().toString(); if (currentDisplay.equals("错误")) { resetCalculator(); updateDisplay("0"); return; } if (currentDisplay.length() > 1) { updateDisplay(currentDisplay.substring(0, currentDisplay.length() - 1)); } else { updateDisplay("0"); isNewNumber = true; } } /** * 处理正负号切换按钮点击事件 */ private void onPlusMinusClick() { String currentDisplay = displayTextView.getText().toString(); if (currentDisplay.equals("错误")) return; if (currentDisplay.startsWith("-")) { updateDisplay(currentDisplay.substring(1)); } else if (!currentDisplay.equals("0")) { updateDisplay("-" + currentDisplay); } } /** * 处理百分号按钮点击事件 */ private void onPercentClick() { try { double value = Double.parseDouble(displayTextView.getText().toString()); double result = value / 100; updateDisplay(formatResult(result)); isNewNumber = true; } catch (NumberFormatException e) { updateDisplay("错误"); } } /** * 处理平方根按钮点击事件 */ private void onSqrtClick() { try { double value = Double.parseDouble(displayTextView.getText().toString()); if (value < 0) { updateDisplay("无效输入"); resetOnNextInput = true; return; } double result = Math.sqrt(value); updateDisplay(formatResult(result)); expressionTextView.setText("√(" + value + ")"); isNewNumber = true; resetOnNextInput = true; } catch (NumberFormatException e) { updateDisplay("错误"); } } /** * 处理平方按钮点击事件 */ private void onSquareClick() { try { double value = Double.parseDouble(displayTextView.getText().toString()); double result = value * value; updateDisplay(formatResult(result)); expressionTextView.setText("sqr(" + value + ")"); isNewNumber = true; resetOnNextInput = true; } catch (NumberFormatException e) { updateDisplay("错误"); } } /** * 处理倒数按钮点击事件 */ private void onReciprocalClick() { try { double value = Double.parseDouble(displayTextView.getText().toString()); if (value == 0) { updateDisplay("不能除以零"); resetOnNextInput = true; return; } double result = 1 / value; updateDisplay(formatResult(result)); expressionTextView.setText("1/(" + value + ")"); isNewNumber = true; resetOnNextInput = true; } catch (NumberFormatException e) { updateDisplay("错误"); } } /** * 格式化计结果 * * @param result 计结果 * @return 格式化后的字符串 */ private String formatResult(double result) { // 如果是整数,不显示小数点 if (result == (long) result) { return String.valueOf((long) result); } else { // 处理浮点数精度问题,保留合适的数 String resultStr = String.format("%.10f", result); // 移除末尾的0 resultStr = resultStr.replaceAll("0*$", "").replaceAll("\\.$", ""); return resultStr; } } /** * 更新显示屏显示内容 * @param value 要显示的值 */ /** * 更新显示屏显示内容 * * @param value 要显示的值 */ private void updateDisplay(String value) { // 处理显示长度限制 String digitsOnly = value.replace(".", "").replace("-", ""); if (digitsOnly.length() >= 10) { value = value.substring(0, 10); } displayTextView.setText(value); } /** * 重置计器状态 */ private void resetCalculator() { previousValue = 0; pendingOperator = ""; isNewNumber = true; resetOnNextInput = false; } /** * 处理记忆清除按钮点击事件 (MC) */ private void onMemoryClearClick() { memoryValue = 0; tv_mr.setTextColor(Color.parseColor("#808080")); tv_mc.setTextColor(Color.parseColor("#808080")); } /** * 处理记忆调用按钮点击事件 (MR) */ private void onMemoryRecallClick() { updateDisplay(formatResult(memoryValue)); isNewNumber = true; tv_mr.setTextColor(Color.BLACK); tv_mc.setTextColor(Color.BLACK); } /** * 处理记忆加法按钮点击事件 (M+) */ private void onMemoryAddClick() { try { double currentValue = Double.parseDouble(displayTextView.getText().toString()); memoryValue += currentValue; tv_mr.setTextColor(Color.BLACK); tv_mc.setTextColor(Color.BLACK); } catch (NumberFormatException e) { // 忽略无效数字 } } /** * 处理记忆减法按钮点击事件 (M-) */ private void onMemorySubtractClick() { try { double currentValue = Double.parseDouble(displayTextView.getText().toString()); memoryValue -= currentValue; tv_mr.setTextColor(Color.BLACK); tv_mc.setTextColor(Color.BLACK); } catch (NumberFormatException e) { // 忽略无效数字 } } /** * 处理记忆存储按钮点击事件 (MS) */ private void onMemoryStoreClick() { try { memoryValue = Double.parseDouble(displayTextView.getText().toString()); tv_mr.setTextColor(Color.BLACK); tv_mc.setTextColor(Color.BLACK); } catch (NumberFormatException e) { updateDisplay("错误"); } } } <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:background="#ECECEC" android:padding="10dp"> <LinearLayout android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="0.4" android:orientation="horizontal"> <ImageView android:padding="2dp" android:layout_width="30dp" android:layout_height="30dp" android:src="@drawable/img_jisuanqi"/> <TextView android:layout_width="0dp" android:layout_height="30dp" android:layout_weight="1" android:text="计器" android:textColor="#000000" android:textSize="15sp" android:layout_marginLeft="8dp" android:gravity="center_vertical"/> <ImageView android:layout_width="60dp" android:layout_height="30dp" android:src="@drawable/img_jianhao" android:padding="6dp"/> <ImageView android:layout_width="60dp" android:layout_height="30dp" android:padding="6dp" android:src="@drawable/img_square"/> <ImageView android:layout_width="60dp" android:layout_height="30dp" android:padding="6dp" android:src="@drawable/img_cha"/> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="0.6" android:orientation="horizontal" android:layout_marginTop="10dp" android:gravity="center"> <ImageView android:padding="6dp" android:layout_width="30dp" android:layout_height="30dp" android:src="@drawable/img_gang"/> <TextView android:layout_width="wrap_content" android:layout_height="match_parent" android:text="标准" android:textColor="#000000" android:textSize="30sp" android:textStyle="bold" android:layout_marginLeft="8dp" android:gravity="center_vertical"/> <ImageView android:layout_width="0dp" android:layout_height="30dp" android:layout_weight="1" android:scaleType="fitStart" android:src="@drawable/img_top"/> <ImageView android:layout_width="30dp" android:layout_height="30dp" android:padding="6dp" android:src="@drawable/img_lishi"/> </LinearLayout> <HorizontalScrollView android:id="@+id/scrollView_1" android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="0.5" android:scrollbars="none" android:background="@drawable/biankuang"> <EditText android:textColor="#808080" android:id="@+id/editText_1" android:layout_width="wrap_content" android:layout_height="match_parent" android:textSize="30sp" android:focusable="false" android:focusableInTouchMode="false" android:clickable="true" android:cursorVisible="false" android:background="@null" android:maxLines="1" android:scrollHorizontally="true" android:inputType="none" android:layout_gravity="right|center"/> </HorizontalScrollView> <HorizontalScrollView android:id="@+id/scrollView" android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" android:background="@drawable/biankuang" android:scrollbars="none"> <EditText android:id="@+id/editText" android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_gravity="right|center" android:background="@null" android:clickable="true" android:cursorVisible="false" android:focusable="false" android:focusableInTouchMode="false" android:inputType="none" android:maxLines="1" android:scrollHorizontally="true" android:text="0" android:textSize="60sp" /> </HorizontalScrollView> <LinearLayout android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="0.5" android:orientation="horizontal"> <TextView android:id="@+id/tv_mc" android:layout_width="0dp" android:layout_height="30dp" android:layout_weight="1" android:gravity="center" android:text="MC" android:textSize="15dp" android:textColor="#808080"/> <TextView android:id="@+id/tv_mr" android:layout_width="0dp" android:layout_height="30dp" android:layout_weight="1" android:gravity="center" android:text="MR" android:textSize="15dp" android:textColor="#808080"/> <TextView android:id="@+id/tv_m_plus" android:layout_width="0dp" android:layout_height="30dp" android:layout_weight="1" android:gravity="center" android:text="M+" android:textColor="@color/black" android:textSize="15dp" /> <TextView android:id="@+id/tv_m_minus" android:layout_width="0dp" android:layout_height="30dp" android:layout_weight="1" android:gravity="center" android:text="M-" android:textColor="@color/black" android:textSize="15dp" /> <TextView android:id="@+id/tv_ms" android:layout_width="0dp" android:layout_height="30dp" android:layout_weight="1" android:gravity="center" android:text="MS" android:textColor="@color/black" android:textSize="15dp" /> <TextView android:layout_width="0dp" android:layout_height="30dp" android:layout_weight="1" android:gravity="center" android:text="M⋁" android:textSize="15dp" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="7" android:orientation="vertical"> <LinearLayout android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1"> <Button android:id="@+id/btn_symbol_percent" android:layout_gravity="center" android:text="%" android:textSize="20sp" android:layout_width="0dp" android:layout_height="55dp" android:layout_margin="3dp" android:layout_weight="1" android:background="@drawable/rounded_button_background" /> <Button android:id="@+id/btn_clear_entry" android:layout_gravity="center" android:text="CE" android:textSize="20sp" android:textColor="@color/black" android:layout_width="0dp" android:layout_height="55dp" android:layout_margin="3dp" android:layout_weight="1" android:background="@drawable/rounded_button_background"/> <Button android:id="@+id/btn_clear" android:layout_gravity="center" android:text="C" android:textSize="20sp" android:textColor="@color/black" android:layout_width="0dp" android:layout_height="55dp" android:layout_margin="3dp" android:layout_weight="1" android:background="@drawable/rounded_button_background"/> <ImageView android:id="@+id/btn_clear_image" android:layout_gravity="center" android:layout_width="0dp" android:layout_height="55dp" android:layout_margin="3dp" android:layout_weight="1" android:padding="10dp" android:background="@drawable/rounded_button_background" android:scaleType="fitCenter" android:src="@drawable/img_qingchu" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1"> <Button android:id="@+id/btn_symbol_x_inverse" android:layout_gravity="center" android:layout_width="0dp" android:layout_height="55dp" android:layout_margin="3dp" android:layout_weight="1" android:background="@drawable/rounded_button_background" android:text="1/x" android:textColor="@color/black" android:textSize="20sp"/> <Button android:id="@+id/btn_symbol_square" android:layout_gravity="center" android:text="x²" android:textSize="20sp" android:textColor="@color/black" android:layout_width="0dp" android:layout_height="55dp" android:layout_margin="3dp" android:layout_weight="1" android:background="@drawable/rounded_button_background" /> <ImageView android:id="@+id/btn_symbol_square_root" android:layout_gravity="center" android:src="@drawable/img_sqrt" android:padding="18dp" android:layout_width="0dp" android:layout_height="55dp" android:layout_margin="3dp" android:layout_weight="1" android:background="@drawable/rounded_button_background"/>\ <Button android:id="@+id/btn_symbol_divide" android:layout_gravity="center" android:text="÷" android:textSize="20sp" android:textColor="@color/black" android:layout_width="0dp" android:layout_height="55dp" android:layout_margin="3dp" android:layout_weight="1" android:background="@drawable/rounded_button_background"/> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1"> <Button android:id="@+id/btn_num_7" android:layout_gravity="center" android:layout_width="0dp" android:layout_height="55dp" android:layout_margin="3dp" android:layout_weight="1" android:background="@drawable/other_button_background" android:text="7" android:textColor="@color/black" android:textSize="20sp" /> <Button android:id="@+id/btn_num_8" android:layout_width="0dp" android:layout_height="55dp" android:layout_gravity="center" android:layout_margin="3dp" android:layout_weight="1" android:background="@drawable/other_button_background" android:text="8" android:textColor="@color/black" android:textSize="20sp" /> <Button android:id="@+id/btn_num_9" android:layout_gravity="center" android:text="9" android:textSize="20sp" android:textColor="@color/black" android:layout_width="0dp" android:layout_height="55dp" android:layout_margin="3dp" android:layout_weight="1" android:background="@drawable/other_button_background"/>\ <Button android:id="@+id/btn_symbol_multiply" android:layout_gravity="center" android:text="×" android:textSize="20sp" android:textColor="@color/black" android:layout_width="0dp" android:layout_height="55dp" android:layout_margin="3dp" android:layout_weight="1" android:background="@drawable/rounded_button_background"/> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1"> <Button android:id="@+id/btn_num_4" android:layout_gravity="center" android:layout_width="0dp" android:layout_height="55dp" android:layout_margin="3dp" android:layout_weight="1" android:background="@drawable/other_button_background" android:text="4" android:textColor="@color/black" android:textSize="20sp" /> <Button android:id="@+id/btn_num_5" android:layout_gravity="center" android:text="5" android:textSize="20sp" android:textColor="@color/black" android:layout_width="0dp" android:layout_height="55dp" android:layout_margin="3dp" android:layout_weight="1" android:background="@drawable/other_button_background" /> <Button android:id="@+id/btn_num_6" android:layout_width="0dp" android:layout_height="55dp" android:layout_gravity="center" android:layout_margin="3dp" android:layout_weight="1" android:background="@drawable/other_button_background" android:text="6" android:textColor="@color/black" android:textSize="20sp" /> <Button android:id="@+id/btn_symbol_minus" android:layout_gravity="center" android:text="-" android:textSize="20sp" android:textColor="@color/black" android:layout_width="0dp" android:layout_height="55dp" android:layout_margin="3dp" android:layout_weight="1" android:background="@drawable/rounded_button_background"/> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1"> <Button android:id="@+id/btn_num_1" android:layout_gravity="center" android:layout_width="0dp" android:layout_height="55dp" android:layout_margin="3dp" android:layout_weight="1" android:background="@drawable/other_button_background" android:text="1" android:textColor="@color/black" android:textSize="20sp" /> <Button android:id="@+id/btn_num_2" android:layout_gravity="center" android:text="2" android:textSize="20sp" android:textColor="@color/black" android:layout_width="0dp" android:layout_height="55dp" android:layout_margin="3dp" android:layout_weight="1" android:background="@drawable/other_button_background" /> <Button android:id="@+id/btn_num_3" android:layout_gravity="center" android:text="3" android:textSize="20sp" android:textColor="@color/black" android:layout_width="0dp" android:layout_height="55dp" android:layout_margin="3dp" android:layout_weight="1" android:background="@drawable/other_button_background"/>\ <Button android:id="@+id/btn_symbol_plus" android:layout_gravity="center" android:text="+" android:textSize="20sp" android:textColor="@color/black" android:layout_width="0dp" android:layout_height="55dp" android:layout_margin="3dp" android:layout_weight="1" android:background="@drawable/rounded_button_background"/> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1"> <Button android:id="@+id/btn_symbol_plus_minus" android:layout_gravity="center" android:layout_width="0dp" android:layout_height="55dp" android:layout_margin="3dp" android:layout_weight="1" android:background="@drawable/other_button_background" android:text="+/-" android:textColor="@color/black" android:textSize="20sp" /> <Button android:id="@+id/btn_num_0" android:layout_gravity="center" android:text="0" android:textSize="20sp" android:textColor="@color/black" android:layout_width="0dp" android:layout_height="55dp" android:layout_margin="3dp" android:layout_weight="1" android:background="@drawable/other_button_background" /> <Button android:id="@+id/btn_num_dot" android:layout_gravity="center" android:text="." android:textSize="20sp" android:textColor="@color/black" android:layout_width="0dp" android:layout_height="55dp" android:layout_margin="3dp" android:layout_weight="1" android:background="@drawable/other_button_background"/>\ <Button android:id="@+id/btn_symbol_equals" android:layout_width="0dp" android:layout_height="55dp" android:layout_gravity="center" android:layout_margin="3dp" android:layout_weight="1" android:background="@drawable/equals" android:text="=" android:textColor="@color/black" android:textSize="20sp" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1.2"> </LinearLayout> </LinearLayout> </LinearLayout>解析每个步骤并详细解释对应的功能
10-21
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值