我理解二进制是如何工作的,我可以计算二进制到十进制,但我在签名数字周围丢失了.我找到了一个可以进行转换的计算器.但我不确定如何找到最大值和最小值或转换如果没有给出二进制数,StackO中的问题似乎是关于转换特定数字或不包括带符号数字到特定位.
具体问题是:
We have only 5 bits for representing signed numbers in two's complement:
What is the highest signed integer?
Write its decimal value (including the sign only if negative).
What is the lowest signed integer?
Write its decimal value (including the sign only if negative).
Run Code Online (Sandbox Code Playgroud)
好像我必须在二进制概念上更重,我只有2个月的编程,我以为我知道二进制转换.
这个问题必须使用递归来解决.
我试图在"else"之后使用代码来使用int temp来查找商,该int计算可以分割的次数(temp = dividend - divisor).
int r应该是商,但由于division()不是int而是数组,所以我不能应用递归.我也尝试在result [0]中插入division(),但同样的,返回是一个数组,而不是一个int.
结果是一个包含2个元素的数组:商和除法的余数.
我一直在练习递归,但我迷失在递归和数组的混合中
我可以用for循环解决这个问题,但正如我所说,必须使用递归.
只应修改else和return之间的代码.如果这应该很容易,我看不到它.
我之前一直在寻找答案,但我发现的那些使用int作为返回,而不是数组.
这是我测试失败的代码(正如您在Main中看到的那样,测试红利为13,除数为3):
public class Main{
/*
* Returns an array with the quotient and remainder of the
* integer division
*
* @param dividend a positive int
* @param divisor a positive int
*/
static int[] division(int dividend, int divisor){
int result[] = {0, dividend};
if ( dividend < divisor ){
return result;
} else{
***int temp = dividend - …Run Code Online (Sandbox Code Playgroud)