base-conversion

Convert decimal to balanced Heptavintimal

允我心安 提交于 2021-01-27 06:31:37
问题 I'm trying to make a function to convert decimal to balanced Heptavintimal (0123456789ABCDEFGHKMNPRTVXZ) where 0 represent -13, D : 0 and Z 13 I have tried this but some cases are not working properly: static const std::string HEPT_CHARS = "0123456789ABCDEFGHKMNPRTVXZ"; std::string heptEnc(int value){ std::string result = ""; do { int pos = value % 27; result = std::string(HEPT_CHARS[(pos + 13)%27] + result); value = value / 27; } while (value != 0); return result; } Here is what I get in

Converting binary to decimal integer output

馋奶兔 提交于 2021-01-21 06:47:11
问题 I need to convert a binary input into a decimal integer. I know how to go from a decimal to a binary: n = int(raw_input('enter a number: ')) print '{0:b}'.format(n) I need to go in the reverse direction. My professor said that when he checks our code, he is going to input 11001 , and he should get 25 back. I've looked through our notes, and I cannot figure out how to do this. Google and other internet resources haven't been much help either. The biggest problem is that we are not allowed to

Converting binary to decimal integer output

拜拜、爱过 提交于 2021-01-21 06:47:11
问题 I need to convert a binary input into a decimal integer. I know how to go from a decimal to a binary: n = int(raw_input('enter a number: ')) print '{0:b}'.format(n) I need to go in the reverse direction. My professor said that when he checks our code, he is going to input 11001 , and he should get 25 back. I've looked through our notes, and I cannot figure out how to do this. Google and other internet resources haven't been much help either. The biggest problem is that we are not allowed to

Converting binary to decimal integer output

£可爱£侵袭症+ 提交于 2021-01-21 06:46:09
问题 I need to convert a binary input into a decimal integer. I know how to go from a decimal to a binary: n = int(raw_input('enter a number: ')) print '{0:b}'.format(n) I need to go in the reverse direction. My professor said that when he checks our code, he is going to input 11001 , and he should get 25 back. I've looked through our notes, and I cannot figure out how to do this. Google and other internet resources haven't been much help either. The biggest problem is that we are not allowed to

C code for converting decimal to any base (from 2 to 36)

蓝咒 提交于 2020-06-27 15:34:10
问题 I have just recently started learning C. I wrote a very short program that converts between decimal and binary. I wanted to try and write a code that converts between decimal and any base (up until 36). However, my code just prints out garbage. #include <stdio.h> #include <string.h> void printBase(int n, int k, int i, char a[]) { int placeholder; if (n != 0) { //return n % 2 + 10 * printBinary(n / 2); placeholder=(char)(n%k); if(placeholder>=10) { a[i] = (char)(placeholder - 10) + 'A'; } else

Decimal to Binary Conversion ASM 3 digits

筅森魡賤 提交于 2020-06-01 05:22:30
问题 I was given a task to convert decimal input numbers and output its binary equivalent via an "array" using assembly. I've the code complete and working, trouble is it only accepts numbers 0-99 for conversion. Ideally, the program should be able to convert any number at least up to 255 decimal so that the code can be reusable for future practices where I might need to handle different 16 bit values within registers. I appreciate all advice given, the code is as follows: .model small .stack

Store SHA-1 in database in less space than the 40 hex digits

喜欢而已 提交于 2020-02-24 11:54:48
问题 I am using a hash algorithm to create a primary key for a database table. I use the SHA-1 algorithm which is more than fine for my purposes. The database even ships an implementation for SHA-1. The function computing the hash is returning a hex value as 40 characters. Therefore I am storing the hex characters in a char(40) column. The table will have lots of rows, >= 200 Mio. rows which is why I am looking for less data intensive ways of storing the hash. 40 characters times ~200 Mio. rows

Convert non terminating binary number to decimal

孤街醉人 提交于 2020-01-24 15:13:12
问题 I don't know how to convert a non terminating binary number(fraction) to decimal . Can anybody guide me how to do with an example? 回答1: if the binary number is a unterminated integer, it would be infinite (positive or negative). How can you represent infinite number in decimal? I think it's ∞ . else if the binary number is a float-point number, congratulations. In many standard of float-point number(e.g., IEEE 754), the mantissa is represented by a binary pattern in which the highest bit has

Negative 64bit Decimal Number to Binary in php

别说谁变了你拦得住时间么 提交于 2020-01-05 06:38:57
问题 I am trying to convert a decimal number for example -268427136 to binary and vice versa. If I try with windows Calc, binary notation for this number is: 1111111111111111111111111111111111110000000000000010000010000000 If I try bindec,decbin or base_convert: echo(decbin(-268427136)); Outputs: 11110000000000000010000010000000 Or echo(bindec('1111111111111111111111111111111111110000000000000010000010000000'); Outputs: 1.84467440734E+19 What could I use in php to achieve same result? 回答1: Your

How to Print Hexadecimal Numbers in PHP or Java

放肆的年华 提交于 2019-12-30 04:15:14
问题 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