标签: base-conversion

如何在PHP中将base64转换为base10?

我目前在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)

php algorithm base-conversion

1
推荐指数
1
解决办法
3383
查看次数

基础10到java中的基础2,8,16转换

我在这个面向对象的课程,但我只是不知道如何做到这一点.我知道基本的基本原理但不是这样的.我被要求创建一个程序,将#的基数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)

java string binary base-conversion

1
推荐指数
1
解决办法
6万
查看次数

左移的十进制除法

我已经给出了一个问题,将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.它可以生成提醒(根据哪些数学运算和逻辑)?

c++ base-conversion bit-shift bitwise-and c++11

1
推荐指数
1
解决办法
6999
查看次数

Convert Binary to Decimal in MIPS, Assembly MARS

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 …

assembly base-conversion mips mars-simulator

1
推荐指数
1
解决办法
1万
查看次数

按顺序生成带有预定义字符的5位字母数字代码

我想生成一个由字母数字字符组成的会员号码,删除i ol在输入时节省混淆.要在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生成的方式进行计数.

我希望我已经解释得这么好了.

php alphanumeric base-conversion id

1
推荐指数
1
解决办法
294
查看次数

将非十进制数转换为另一个非十进制数

这不是很多工作,但我知道将非十进制转换为另一个非小数的唯一方法是先将数字转换为十进制,然后再采取第二步将其转换为新的基数.例如,要将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)

algorithm base-conversion

0
推荐指数
1
解决办法
719
查看次数

如何将Hexa-Tri-Decimal数转换为目标c中的int?

Hexa-Tri-Decimal数字是0-9和AZ.我知道我可以使用NSScanner从hex转换,但不知道如何转换Hexa-Tri-Decimal.

例如,我有一个带有"0XPM"的NSString,int值应该是43690,"1BLC"将是61680.

base-conversion objective-c

0
推荐指数
1
解决办法
767
查看次数

算法将未知基数中的数字转换为等效的基数10

可能重复:
数字系统之间转换的高效算法

给定一个整数,编写一个程序,将给定的数字转换为数字(基数为10).提示 - 给定的数字可以在任何基础上,但基数是未知的.

algorithm base-conversion

-6
推荐指数
2
解决办法
6902
查看次数