好吧,第一次在这里发布任何东西,所以我们开始
我刚开始学习编程,我的教授给了我们一个巨大的不可能的问题(至少对我来说是这样),在不使用bin()或十六进制()这样的函数的情况下完成基本转换。
Bin -> Dec, Hex, Oct
Dec -> Bin, Hex, Oct
Hex -> Bin, Dec, Oct
Oct -> Bin, Dec, Hex
到目前为止,我已经能够编码(我认为)其中的3个(二进制到十进制,十进制到二进制,十进制到八进制),但是我似乎找不到一种从十进制到十六进制的方法。到目前为止,这就是我所掌握的(全部都是蟒蛇)
# BI
我试图找出如何根据可用的字母表将一个数字转换成一个字符串,并考虑一个最小的字符串长度。
例如:
考虑到我有这样的字母表: AB12,并且我定义最小字符串长度为:2
The number 1 would be = AA
The number 2 would be = AB
The number 3 would be = A1
The number 4 would be = A2
The number 5 would be = BA
The number 6 would be = BB
The number 7 would be = B1
The number 8 would be = B2
Th
我有一个家庭作业,我必须将任何基数转换为基数10。我有一些给定的数字,它们是“基数”。我必须将这些基数转换为基数10。我唯一陷入的部分是代码的这一部分:
answer = ; // Not sure what I have to put in here
我看过其他一些关于转换到基数10的帖子,但我只是不确定如何将它们合并到我的代码中。
public class BaseN {
public static final int BASEN_ERRNO = -1;
public static int digit = 0;
public static void main(String[] arg
我想在Julia中将整数转换为字符串。
当我尝试的时候:
a = 9500
b = convert(String,a)
我得到了错误:
ERROR: LoadError: MethodError: Cannot `convert` an object of type Int64 to an object of type String
This may have arisen from a call to the constructor String(...),
since type constructors fall back to convert methods.
in include_f
#include <iostream>
using namespace std;
int main()
{
long int b2 = 0;
long int i = 1;
int x;
cout << "Enter a number:" ;
cin >> x ;
int y = x;
while (x!=0) {
if ( x%2 )
{
b2 = b2 + i;
}
i = i*1
我读过官方的医生,但仍然很困惑。
我在我的终端上尝试了一些命令,我找到了一些规则,但仍然不太清楚。希望对此有更多了解的人能进一步解释。
以下是我的例子和调查结果:
int('0', base=1)
ValueError: int() base must be >= 2 and <=36
int('3', base=2)
ValueError: invalid literal for int() with base 2:
int('3', base=4)
3
int('33', base=4)
15
int(
我现在开始使用Julia,我需要插值一个布朗运动。我运行了以下代码,但出现了以下错误。 N = 3
B = zeros(N)
B[N] = randn(1) 这会抛出: MethodError: Cannot `convert` an object of type Vector{Float64} to an object of type Float64
b = 15
a = bin(b) # I want return as an integer not string
print(a, type(a)) # output is string, actually I want is integer
# output - 0b1111 <class 'str'>
因此,我想让bin()函数以整数形式返回
我想通过将长度为h的较小列向量G重复n次来创建列向量X。
G = [1;2;3;4] #column vector of length h
X = [1;2;3;4;1;2;3;4;1;2;3;4] #ie X = [G;G;G;G] column vector of
length h*n
当我尝试在这种情况下使用fill时,我得到的不是一个长度为h*n的列向量,而是一个长度为n的列向量,其中每一行都是另一个长度为h的向量。例如,我得到了以下内容:
X = [[1,2,3,4];[1,2,3,4];[1,2,3,4];[1,2,3,4]]
这对我来说没有任何意义,因为我知道;符号用于显示行中的
我用Matlab生成一个复数向量,我想把这个向量保存到文本文件(.txt)中,以便在我的C代码中使用它作为输入,所以复数向量如下所示:
y = zeros(1,N);
for n = 1:N
y(n) = exp(-1i*(n-1)*k*d*sind(Qtgt));
end
因此,我尝试使用函数dlmwrite将向量保存为文本文件:
dlmwrite('data.txt', y, 'delimiter','\n','newline', 'pc')
向量存储如下:
但我希望它是这样存储的:每个复
我知道Integer.parseInt()函数的基数是将字符串转换成的基数。用基数/基数16转换的11基数10不应该是B而不是17吗
下面的代码根据教科书打印17:
public class Test {
public static void main(String[] args) {
System.out.println( Integer.parseInt("11", 16) );
}
}
我只是好奇如何使用Ruby程序,而不是宝石,将一个数字从基数m转换为另一个基数n。有没有人这样做过,并愿意分享他们的想法或想法?我只是觉得尝试这样的程序会很有趣:)
我已经从bin到dec,从dec到bin,从dex到hex,从hex到dec,但是我想知道如何从m到n。
def bin2dec(num)
sum = 0
i = 0
while i < num.length
sum += 2 ** i * num[num.length - i - 1].to_i
i += 1
end
return sum
end
bin = gets.chomp