十六进制加法 [英] Hexadecimal Addition

查看:117
本文介绍了十六进制加法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够添加两个十六进制数字。下面是代码。这段代码用于从十六进制转换为十进制,所以我想要的是当我输入第二个十六进制值时,它转换为十进制,然后添加两个,然后转换回十六进制并显示添加的十六进制值。


I want to be able to add two hexadecimal numbers . Below is the code. This code is for converting from hexadecimal to decimal, so what I want is that when I enter the second Hexadecimal value, it converts to Decimal and then adds both and then converts back to Hexadecimal and displays the added Hexadecimal value.


展开 | 选择 | Wrap | 行号

推荐答案

想知道为什么要这样做?

十六进制只是另一种格式。您可以使用十六进制格式工作,就像您可以使用十六进制格式一样工作

如果x = 2b4(692)和y = 3c7(967)

x + y = 67b( 1659)
Wonder why you would want to do that?
hexadecimal is just another format. You can work in hex format just as you can work in dec format
if x=2b4 (692) and y=3c7 (967)
x+y=67b (1659)


这实际上是一个Hexa-to-deci转换代码...所以我想出了将两个hexa转换为deci并将它们加在一起的解决方案但是我得到了以十进制形式回答...所以如何使用上面的代码将十进制形式转换为十六进制形式并且不添加全新的代码集
This is actually a Hexa-to-deci converting code...so I''ve come up with the solution to convert two hexa to deci and add them together but im getting answer in decimal form...so how do I convert decimal form to hexadecimal form with the above codes and without adding whole new sets of codes


我一遍又一遍地看到同样的混淆再次在这个论坛上。 Bil M,请不要为这个回复感到沮丧;提出这个问题的许多其他人提示的比你写的更多。


当你说你想要添加十六进制时,专家会感到困惑,或者你想添加十进制数字,或者你想添加一些其他类型的数字,因为计算机只识别一种数字:二进制。


你想要做的是
  • 允许操作员输入以某种格式表示的数字。格式是隐式的(''我的程序只接受十六进制'')或它是显式的(0x前缀表示十六进制等)。
  • 将运算符输入的数字存储到字符串中。
  • 将该字符串转换为数字。
  • 对该数字执行某些操作。
  • 根据某种所需格式将结果编号转换为字符串表示形式。
  • 打印结果的字符串表示。
I see this same kind of confusion over and over again in this forum. Bil M, please don''t be upset over this reply; it is prompted more by the many other folks who posed this question than it is by what you wrote.

The experts get confused when you say you want to add hexadecimals, or you want to add decimal numbers, or you want to add some other kind of numbers, because the computer only recognizes one kind of number: binary.

What you want to do is
  • Allow the operator to enter a number that is expressed in some format. Either the format is implicit (''my program only accepts hexadecimal'') or it is explicit ("0x" prefix means hexadecimal, etc).
  • Store the operator''s entered number into a string.
  • Convert that string to a number.
  • Perform some operation on that number.
  • Convert the result number into a string representation according to some desired format.
  • Print the string representation of the result.


这篇关于十六进制加法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆