base-conversion

How can I convert a number in a string to any base in assembly?

陌路散爱 提交于 2019-12-02 06:37:01
How can I convert a number contained in a string from any base to any other base? Bases can be anything i.e.: 2, 16, 10, 4, 8, 9. I'm expecting the user to enter the base number. The user will enter the output base (the base to be converted to). The user will enter the number he wants to convert. Pre thoughts: I will save the input base and the output base in variables. Then I'll save the number he enters in a string (because he could enter any kind of number (hex, binary, base-5..). I'm just trying to figure out how to convert that string to a number so i can convert it to the output base.

c++ template for conversion between decimal and arbitrary base

…衆ロ難τιáo~ 提交于 2019-12-02 05:01:44
问题 Is there a c++ structure or template (in any library) that allows me to do conversion between decimal and any other base (much like what bitset can do) ? 回答1: Yes, you can use unsigned int : unsigned int n = 16; // decimal input unsigned int m = 0xFF; // hexadecimal input std::cout << std::dec << "Decimal: " << n << ", " << m << std::endl; std::cout << std::hex << "Hexadecimal: 0x" << n << ", 0x" << m << std::endl; Octal is also supported, though for other bases you had best write your own

c++ template for conversion between decimal and arbitrary base

随声附和 提交于 2019-12-01 22:59:20
Is there a c++ structure or template (in any library) that allows me to do conversion between decimal and any other base (much like what bitset can do) ? Yes, you can use unsigned int : unsigned int n = 16; // decimal input unsigned int m = 0xFF; // hexadecimal input std::cout << std::dec << "Decimal: " << n << ", " << m << std::endl; std::cout << std::hex << "Hexadecimal: 0x" << n << ", 0x" << m << std::endl; Octal is also supported, though for other bases you had best write your own algorithm - it's essentially a three-liner in C++: std::string to_base(unsigned int n, unsigned int base) {

Base 10 to base n conversions [closed]

白昼怎懂夜的黑 提交于 2019-11-30 13:17:24
问题 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 7 years ago . I'm trying to write a C++ program that does base-conversions. I want to convert a decimal number to all the other integer bases from 2 to 20. Is there an efficient and easy-to-implement algorithm for base

How to Print Hexadecimal Numbers in PHP or Java

时光总嘲笑我的痴心妄想 提交于 2019-11-30 12:34:40
I need to print some data (a little bit strange formatted). I was writing it in PHP with if ($num%10==9) but it was impossible for me to get correct output. So take a look at this for example. We have x of files in folder. For this example x=36. X is always known. Output should look like this: 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f 10 11 ... 19 1a ... 1f 20 ... 24 Sorry for the such a long "list" but I believe that you know what I need now. So, after each number which ends with 9 we have num(a,b,c,d,e,f) and then number which follows previous number with 9 on the end. (Ex. 3a...3f,40..49

Computing the Factoradic Rank of a Permutation (N choose K)

岁酱吖の 提交于 2019-11-29 08:12:26
I've recently learnt about CNS and FNS , and since they look so elegant to me, I decided to try and implement methods to generate combinations and permutations using those techniques. I finished my method to convert from n choose k combinations to a CSN rank and vice-versa but I'm banging my head against the wall trying to do the same with n choose k (unique) permutations. Thanks to @Joshua I got the unranking (FNS to permutation) method working: function Pr_Unrank($n, $k, $rank) { // rank starts at 1 if ($n >= $k) { if (($rank > 0) && ($rank <= Pr($n, $k))) { $rank--; $result = array();

Calculating the negabinary representation of a given number without loops

纵饮孤独 提交于 2019-11-29 07:10:51
Could you provide a convincing explanation, or a mathematical proof, to why the following function calculates the negabinary representation of a given number? function quickNegabinary(number) { var mask = 0xAAAAAAAA; return ((number + mask) ^ mask).toString(2); } Negabinary notation Negabinary notation uses a radix of -2. This means that, as in every number system with a negative base, every other bit has a negative value: position: ... 7 6 5 4 3 2 1 0 binary: ... 128 64 32 16 8 4 2 1 negabinary: ... -128 +64 -32 +16 -8 +4 -2 +1 Quick conversion method The quick binary→negabinary conversion

PHP - Generate an 8 character hash from an integer

走远了吗. 提交于 2019-11-29 04:37:38
Is there a way to take any number, from say, 1 to 40000 and generate an 8 character hash? I was thinking of using base_convert but couldn't figure out a way to force it to be an 8 character hash. Any help would be appreciated! Nathan Osman Why don't you just run md5 and take the first 8 characters? Because you are wanting a hash, it doesn't matter whether portions are discarded, but rather that the same input will produce the same hash. $hash = substr(md5($num), 0, 8); >>> math.exp(math.log(40000)/8) 3.7606030930863934 Therefore you need 4 digit-symbols to produce a 8-character hash from 40000

Base 10 to base 2,8,16 conversion in java [duplicate]

空扰寡人 提交于 2019-11-28 22:11:36
This question already has an answer here: In Java how do you convert a decimal number to base 36? 10 answers I'm in this Object Oriented class, but I just don't know how to do this. I know basic fundamentals but nothing like this. I am asked to create a program that converts #'s base 10 to base 2, base 8,and base 16. Then, after we are asked to convert it back from 2,8,16 to base 10. I have gathered some information from other websites and I actually ended up editing a bit of it. Please help! I would prefer it if you guys actually helped and edited yourselves and sent it to me, but if that is

Print large base 256 array in base 10 in c

牧云@^-^@ 提交于 2019-11-28 03:22:33
问题 I have an array of unsigned chars in c I am trying to print in base 10, and I am stuck. I think this will be better explained in code, so, given: unsigned char n[3]; char[0] = 1; char[1] = 2; char[2] = 3; I would like to print 197121. This is trivial with small base 256 arrays. One can simply 1 * 256 ^ 0 + 2 * 256 ^ 1 + 3 * 256 ^ 2. However, if my array was 100 bytes large, then this quickly becomes a problem. There is no integral type in C that is 100 bytes large, which is why I'm storing