Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > pl.comp.programming > #29811

Re: Algorytm hex,dec<->liczba

From Borneq <borneq@antyspam.hidden.pl>
Newsgroups pl.comp.programming
Subject Re: Algorytm hex,dec<->liczba
Date 2017-07-04 15:59 +0200
Organization ATMAN - ATM S.A.
Message-ID <ojg70d$dm9$1@node2.news.atman.pl> (permalink)
References <ojbd2k$m8a$1@node1.news.atman.pl> <15b73aa2-1d56-4cb7-ad9a-a2775c073040@googlegroups.com> <ojg3pv$alr$1@node2.news.atman.pl>

Show all headers | View raw


W dniu 04.07.2017 o 15:05, Borneq pisze:
> Tu znalazłem dobrze rozpisane:
> http://www.cs.trincoll.edu/~ram/cpsc110/inclass/conversions.html
> może się przydać

Ostatecznie, trochę pozmieniałem kolejność w baseToNumber
Gotowiec:
#include <string>
#include <boost/multiprecision/cpp_int.hpp>

std::string numberToBase(boost::multiprecision::cpp_int n, int base)
{
	const int max_buf = 128; //128 bit to binary
	char buf[max_buf+1];
	buf[max_buf] = 0;
	int pos = max_buf - 1;
	while (n != 0)
	{
		boost::multiprecision::cpp_int rb = n % base;
		int r = (int)rb;		
		n = n / base;
		char letter;
		if (r < 10)
			letter = '0' + r;
		else
			letter = 'a' + (r - 10);				
		buf[pos] = letter;
		pos--;
	}
	return buf + pos + 1;
}

boost::multiprecision::cpp_int baseToNumber(std::string str, int base)
{	
	boost::multiprecision::cpp_int n = 0;
	for (int i = 0; i< str.length(); i++)
	{
		char letter = tolower(str[i]);
		int r;
		if (letter >= '0' && letter <= '9')
			r = letter - '0';
		else
			r = letter - 'a'  + 10;
		n = n * base + r;
	}
	return n;
}

int main()
{
	std::string strnum =  numberToBase(642452, 16);
	std::cout << strnum << std::endl;
	boost::multiprecision::cpp_int n = baseToNumber(strnum, 16);
	std::cout << n << std::endl;
     return 0;
}


Back to pl.comp.programming | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Algorytm hex,dec<->liczba Borneq <borneq@antyspam.hidden.pl> - 2017-07-02 20:12 +0200
  Re: Algorytm hex,dec<->liczba "M.M." <mmarszik@gmail.com> - 2017-07-03 06:50 -0700
    Re: Algorytm hex,dec<->liczba Borneq <borneq@antyspam.hidden.pl> - 2017-07-03 19:29 +0200
      Re: Algorytm hex,dec<->liczba "M.M." <mmarszik@gmail.com> - 2017-07-03 10:50 -0700
    Re: Algorytm hex,dec<->liczba Borneq <borneq@antyspam.hidden.pl> - 2017-07-04 15:05 +0200
      Re: Algorytm hex,dec<->liczba Borneq <borneq@antyspam.hidden.pl> - 2017-07-04 15:59 +0200
        Re: Algorytm hex,dec<->liczba Borneq <borneq@antyspam.hidden.pl> - 2017-07-05 20:24 +0200
          Re: Algorytm hex,dec<->liczba wół, wół roboczy, wół dojno roboczo obronny 'POPIS/EU <NOSPAMtestowanije@go2.pl> - 2017-07-06 17:05 +0200
            Re: Algorytm hex,dec<->liczba szykcech@gmail.com - 2017-07-06 11:06 -0700
              Re: Algorytm hex,dec<->liczba wół, wół roboczy, wół dojno roboczo obronny 'POPIS/EU <NOSPAMtestowanije@go2.pl> - 2017-07-06 20:21 +0200
                Re: Algorytm hex,dec<->liczba "AK" <nobody@nowhere.net> - 2017-07-07 01:32 +0200
                Re: Algorytm hex,dec<->liczba slawek <fake@fakeemail.com> - 2017-07-10 10:23 +0200
                Re: Algorytm hex,dec<->liczba "AK" <nobody@nowhere.net> - 2017-07-10 17:44 +0200
              Re: Algorytm hex,dec<->liczba wół, wół roboczy, wół dojno roboczo obronny 'POPIS/EU <NOSPAMtestowanije@go2.pl> - 2017-07-06 20:36 +0200
                Re: Algorytm hex,dec<->liczba wół, wół roboczy, wół dojno roboczo obronny 'POPIS/EU <NOSPAMtestowanije@go2.pl> - 2017-07-07 17:10 +0200
                Re: Algorytm hex,dec<->liczba "AK" <nobody@nowhere.net> - 2017-07-07 17:25 +0200
              Re: Algorytm hex,dec<->liczba slawek <fake@fakeemail.com> - 2017-07-10 10:12 +0200
  Re: Algorytm hex,dec<->liczba "M.M." <mmarszik@gmail.com> - 2017-07-03 07:14 -0700
  Re: Algorytm hex,dec<->liczba wół, wół roboczy 'POPIS/EU <NOSPAMtestowanije@go2.pl> - 2017-07-03 17:06 +0200
    Re: Algorytm hex,dec<->liczba szykcech@gmail.com - 2017-07-03 09:17 -0700
      Re: Algorytm hex,dec<->liczba "M.M." <mmarszik@gmail.com> - 2017-07-03 10:23 -0700
        Re: Algorytm hex,dec<->liczba wół, wół roboczy, wół dojno roboczy 'POPIS/EU <NOSPAMtestowanije@go2.pl> - 2017-07-03 20:15 +0200
      Re: Algorytm hex,dec<->liczba wół, wół roboczy, wół dojno roboczy 'POPIS/EU <NOSPAMtestowanije@go2.pl> - 2017-07-03 20:18 +0200
        Re: Algorytm hex,dec<->liczba "M.M." <mmarszik@gmail.com> - 2017-07-03 13:22 -0700
          Re: Algorytm hex,dec<->liczba wół, wół roboczy, wół dojno roboczo obronny 'POPIS/EU <NOSPAMtestowanije@go2.pl> - 2017-07-04 19:02 +0200
            Re: Algorytm hex,dec<->liczba szykcech@gmail.com - 2017-07-04 10:14 -0700
              Re: Algorytm hex,dec<->liczba wół, wół roboczy, wół dojno roboczo obronny 'POPIS/EU <NOSPAMtestowanije@go2.pl> - 2017-07-04 19:26 +0200
                Re: Algorytm hex,dec<->liczba wół, wół roboczy, wół dojno roboczo obronny 'POPIS/EU <NOSPAMtestowanije@go2.pl> - 2017-07-04 19:34 +0200
                Re: Algorytm hex,dec<->liczba szykcech@gmail.com - 2017-07-04 11:10 -0700
                Re: Algorytm hex,dec<->liczba wół, wół roboczy, wół dojno roboczo obronny 'POPIS/EU <NOSPAMtestowanije@go2.pl> - 2017-07-04 20:28 +0200
                Re: Algorytm hex,dec<->liczba szykcech@gmail.com - 2017-07-04 11:34 -0700
                Re: Algorytm hex,dec<->liczba wół, wół roboczy, wół dojno roboczo obronny 'POPIS/EU <NOSPAMtestowanije@go2.pl> - 2017-07-04 20:46 +0200
                Re: Algorytm hex,dec<->liczba szykcech@gmail.com - 2017-07-04 12:11 -0700
                Re: Algorytm hex,dec<->liczba szykcech@gmail.com - 2017-07-04 12:33 -0700
                Re: Algorytm hex,dec<->liczba wół, wół roboczy, wół dojno roboczo obronny 'POPIS/EU <NOSPAMtestowanije@go2.pl> - 2017-07-05 17:20 +0200
                Re: Algorytm hex,dec<->liczba szykcech@gmail.com - 2017-07-06 10:46 -0700
                Re: Algorytm hex,dec<->liczba wół, wół roboczy, wół dojno roboczo obronny 'POPIS/EU <NOSPAMtestowanije@go2.pl> - 2017-07-06 20:20 +0200
                Re: Algorytm hex,dec<->liczba wół, wół roboczy, wół dojno roboczo obronny 'POPIS/EU <NOSPAMtestowanije@go2.pl> - 2017-07-06 20:48 +0200
                Re: Algorytm hex,dec<->liczba "AK" <nobody@nowhere.net> - 2017-07-07 01:31 +0200
                Re: Algorytm hex,dec<->liczba szykcech@gmail.com - 2017-07-07 13:02 -0700
                Re: Algorytm hex,dec<->liczba Borneq <borneq@antyspam.hidden.pl> - 2017-07-07 22:13 +0200
                Re: Algorytm hex,dec<->liczba wół, wół roboczy, wół dojno roboczo obronny 'POPIS/EU <NOSPAMtestowanije@go2.pl> - 2017-07-07 22:28 +0200
                Re: Algorytm hex,dec<->liczba szykcech@gmail.com - 2017-07-08 03:45 -0700
                Re: Algorytm hex,dec<->liczba Wojciech Muła <wojtek.mula@gmail.com> - 2017-07-08 09:40 -0700
                Re: Algorytm hex,dec<->liczba "M.M." <mmarszik@gmail.com> - 2017-07-08 12:40 -0700
                Re: Algorytm hex,dec<->liczba szykcech@gmail.com - 2017-07-09 04:16 -0700
                Re: Algorytm hex,dec<->liczba "AK" <nobody@nowhere.net> - 2017-07-10 07:53 +0200
                Re: Algorytm hex,dec<->liczba slawek <fake@fakeemail.com> - 2017-07-10 10:38 +0200
                Re: Algorytm hex,dec<->liczba szykcech@gmail.com - 2017-07-10 07:22 -0700
                Re: Algorytm hex,dec<->liczba "M.M." <mmarszik@gmail.com> - 2017-07-10 07:51 -0700
                Re: Algorytm hex,dec<->liczba szykcech@gmail.com - 2017-07-10 11:03 -0700
                Re: Algorytm hex,dec<->liczba "M.M." <mmarszik@gmail.com> - 2017-07-10 14:48 -0700
                Re: Algorytm hex,dec<->liczba slawek <fake@fakeemail.com> - 2017-07-11 16:25 +0200
                Re: Algorytm hex,dec<->liczba szykcech@gmail.com - 2017-07-11 07:48 -0700
                Re: Algorytm hex,dec<->liczba slawek <fake@fakeemail.com> - 2017-07-11 17:53 +0200
                Re: Algorytm hex,dec<->liczba Roman Tyczka <noemail@because.no> - 2017-07-12 11:43 +0200
                Re: Algorytm hex,dec<->liczba slawek <fake@fakeemail.com> - 2017-07-12 14:05 +0200
                Re: Algorytm hex,dec<->liczba "AK" <nobody@nowhere.net> - 2017-07-12 20:44 +0200
                Re: Algorytm hex,dec<->liczba szykcech@gmail.com - 2017-07-10 11:13 -0700
                Re: Algorytm hex,dec<->liczba slawek <fake@fakeemail.com> - 2017-07-11 16:20 +0200
                Re: Algorytm hex,dec<->liczba szykcech@gmail.com - 2017-07-11 09:25 -0700
                Re: Algorytm hex,dec<->liczba slawek <fake@fakeemail.com> - 2017-07-11 19:16 +0200
                Re: Algorytm hex,dec<->liczba "M.M." <mmarszik@gmail.com> - 2017-07-11 13:30 -0700
                Re: Algorytm hex,dec<->liczba slawek <fake@fakeemail.com> - 2017-07-11 23:53 +0200
                Re: Algorytm hex,dec<->liczba "M.M." <mmarszik@gmail.com> - 2017-07-11 16:00 -0700
                Re: Algorytm hex,dec<->liczba slawek <fake@fakeemail.com> - 2017-07-12 08:21 +0200
                Re: Algorytm hex,dec<->liczba "M.M." <mmarszik@gmail.com> - 2017-07-12 06:24 -0700
                Re: Algorytm hex,dec<->liczba Tomasz Kaczanowski <kaczus@poczta.onet.pl> - 2017-07-07 07:45 +0200
                Re: Algorytm hex,dec<->liczba "M.M." <mmarszik@gmail.com> - 2017-07-07 05:00 -0700
                Re: Algorytm hex,dec<->liczba "AK" <nobody@nowhere.net> - 2017-07-07 17:18 +0200
                Re: Algorytm hex,dec<->liczba "M.M." <mmarszik@gmail.com> - 2017-07-07 09:51 -0700
                Re: Algorytm hex,dec<->liczba "AK" <nobody@nowhere.net> - 2017-07-10 07:46 +0200
                Re: Algorytm hex,dec<->liczba "M.M." <mmarszik@gmail.com> - 2017-07-10 04:55 -0700
                Re: Algorytm hex,dec<->liczba wół, wół roboczy, wół dojno roboczo obronny 'POPIS/EU <NOSPAMtestowanije@go2.pl> - 2017-07-10 18:08 +0200
                Re: Algorytm hex,dec<->liczba "AK" <nobody@nowhere.net> - 2017-07-10 18:17 +0200
                Re: Algorytm hex,dec<->liczba wół, wół roboczy, wół dojno roboczo obronny 'POPIS/EU <NOSPAMtestowanije@go2.pl> - 2017-07-10 18:40 +0200
                Re: Algorytm hex,dec<->liczba wół, wół roboczy, wół dojno roboczo obronny 'POPIS/EU <NOSPAMtestowanije@go2.pl> - 2017-07-05 17:30 +0200
                Re: Algorytm hex,dec<->liczba w systemie siła 'POPIS/EU <NOSPAMtestowanije@go2.pl> - 2017-07-05 23:06 +0200
      Re: Algorytm hex,dec<->liczba "AK" <nobody@nowhere.net> - 2017-07-05 21:58 +0200
  Re: Algorytm hex,dec<->liczba slawek <fake@fakeemail.com> - 2017-07-10 10:01 +0200

csiph-web