我目前在PHP中将base10数字转换为base64.但我不知道在php中将base64转换为base10!
我该怎么做?
我将base10转换为base64的算法:
$rep = array('0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','-','_');
$new = "";
while ($num>0) {
$r = $num % 64;
$new .= $rep[$r];
$num = floor($num/64);
}
Run Code Online (Sandbox Code Playgroud) 我在这个面向对象的课程,但我只是不知道如何做到这一点.我知道基本的基本原理但不是这样的.我被要求创建一个程序,将#的基数10转换为基数2,基数8和基数16.然后,在我们被要求将其从2,8,16转换回基数10.之后我收集了一些信息从其他网站,我实际上最终编辑了一点.请帮忙!我更喜欢它,如果你们真的帮助和编辑自己并将它发送给我,但如果这太多了,请尝试指导我,因为我不太了解Java.到目前为止,我有:
import java.util.Scanner;
public class baseconverterr
{
public static void main(String[] args) {
// Read the conversion choice from the user
System.out.println("Choose 1 or 2 or 3:");
System.out.println("1: conversion from base 10 to base 2 ");
System.out.println("2: conversion from base 10 to base 8");
System.out.println("3: conversion from base 10 to base 16");
// do you want 1, 2 , or 3? you have your choice
Scanner in = new Scanner(System.in);
int choice = in.nextInt();
String string = in.nextLine();
// Read …Run Code Online (Sandbox Code Playgroud) 我已经给出了一个问题,将base从10转换为2 而不使用除法(/)和模块(%),因此我提出了使用按位AND(&)和右移(>>)运算符的解决方案.
所以我开始了解这两个操作员究竟做了什么,但仍然有些问题我无法回答或理解背后的逻辑.
如果我理解正确的除法工作根据数字的位置值,十进制和二进制两者.当我们将数字除以10或2时,我们将位置值在两者中向右移动一个位置,这将导致十进制除以10,二进制除以二.
X = 120(十进制)如果X >> 1我们将X = 12(除以10)
Y = 1000(以2为基数)如果Y >> 1,我们将X = 100(除以2)
但是当我使用这段代码时:
#include<iostream>
using namespace std ;
int main()
{
int a,b=1;
cout <<"enter an integer"<<endl;
cin>> a;
cout<<(a & b)<<endl;
a=a>>1;
cout<<a;
cout<<endl;
system("pause");
return 0 ;
}
Run Code Online (Sandbox Code Playgroud)
我感到困惑,因为在我看来它就是这样的
a = 120(以十为基数)如果X >> 1,我们将X = 12(除以10)
但结果就是这样
a = 120(以十为基数)如果X >> 1我们有X = 60(除以2 !!)
我不明白结果的两个要点:
第一:如果这个运算符(>>)只是移动代码中数字的位置值并且不改变数字的基数(10)它应该产生另一个结果(12),而不是我们在代码结果中看到的结果(它是60).为什么我们可以看到这个结果(60)而不是12?
第二:如果它是二进制左移(对我来说似乎这样),它是否首先由IDE将十进制更改为二进制?
关于按位AND,如果它是逻辑门(它似乎是):
1.除了0和1以外,我们如何设置其他值并且钢有答案?
2.按位和规则
Y'1 = Y
然后它应该是120但代码的结果是1.这是什么解释?
3.它可以生成提醒(根据哪些数学运算和逻辑)?
I am trying to convert binary to decimal in the MIPS language, using the MARS simulator. The program accepts a binary number, and then does the conversion, by multiplying (shift left by the number's place $t9). Another way of saying that is multiplying each 1 digit by 2 raised to the power of the place, and summing that result.
I do not have a very good understanding of how values are stored and communicated between ascii, decimal, and the problem …
我想生成一个由字母数字字符组成的会员号码,删除i o并l在输入时节省混淆.要在php中完成(如果重要的话也使用Laravel 5.7 - 但我觉得这是一个php问题)
如果只使用0-9,会员编号将从00001开始,第一个人和第11个人将有00011.我想使用0-9 + az的字母数字字符(删除所说的字母)
0-9(总共10个字符),abcdefghjkmnpqrstuvwxyz(共23个字符) - 这在每个计数周期(0-10 + aZ)中总共给出33个字符.而不只是10(0-10)
所以第一个会员号仍然是00001,其中第12个现在是0000a,第14个0000c和第34个将是0001a.
总而言之,我需要一种定义字符的方法,以便可以基于用户的id生成的方式进行计数.
我希望我已经解释得这么好了.
这不是很多工作,但我知道将非十进制转换为另一个非小数的唯一方法是先将数字转换为十进制,然后再采取第二步将其转换为新的基数.例如,要将456(在基数7中)转换为567(在基数8中),我会计算456的十进制值,然后将该值转换为基数8 ...
有没有更好的方法直接从7到8?或任何其他基地的任何基础?
这就是我所拥有的:
//source_lang and target_lang are just the numeric symbols, they would be "0123456789" if they were decimal, and "0123456789abcdef" if hex.
private string translate(string num, string source_lang, string target_lang)
{
int b10 = 0;
string rv = "";
for (int i=num.Length-1; i>=0; i--){
b10 += source_lang.IndexOf( num[i] ) * ((int)Math.Pow(source_lang.Length, num.Length -1 - i));
}
while (b10 > 0) {
rv = target_lang[b10 % target_lang.Length] + rv;
b10 /= target_lang.Length;
}
return rv;
}
Run Code Online (Sandbox Code Playgroud) Hexa-Tri-Decimal数字是0-9和AZ.我知道我可以使用NSScanner从hex转换,但不知道如何转换Hexa-Tri-Decimal.
例如,我有一个带有"0XPM"的NSString,int值应该是43690,"1BLC"将是61680.
可能重复:
数字系统之间转换的高效算法
给定一个整数,编写一个程序,将给定的数字转换为数字(基数为10).提示 - 给定的数字可以在任何基础上,但基数是未知的.
algorithm ×3
php ×2
alphanumeric ×1
assembly ×1
binary ×1
bit-shift ×1
bitwise-and ×1
c++ ×1
c++11 ×1
id ×1
java ×1
mips ×1
objective-c ×1
string ×1