Exetools  

Go Back   Exetools > General > General Discussion

Notices

Reply
 
Thread Tools Display Modes
  #1  
Old 03-13-2020, 02:17
TempoMat TempoMat is offline
Friend
 
Join Date: Jan 2006
Posts: 89
Rept. Given: 10
Rept. Rcvd 6 Times in 6 Posts
Thanks Given: 4
Thanks Rcvd at 28 Times in 21 Posts
TempoMat Reputation: 6
Code snippet for converting a byteArray to Base34

Quote:
Originally Posted by Kurapica View Post
https://gist.github.com/JohannesMP/a911b7dc02bb0586e3111a0cbd2dc0e2

Credits to the original coder.
Thnaks for the link
Howover I have tried that and many others already and this particular one does not work for me, because that code snippet is for bases 2...36.

I forgot to state in my first post that the search is for conversion from ByteArray to Base34.

So to use this code snippet one has to first convert the byteArray (==BigNumber) to Binary or Base10 and then to Base34.

Alternative suggestion is to use BigInteger Library for the division, which I thought I could avoid.
Reply With Quote
  #2  
Old 03-13-2020, 02:37
runio runio is offline
Friend
 
Join Date: Jul 2016
Location: Earth
Posts: 18
Rept. Given: 0
Rept. Rcvd 0 Times in 0 Posts
Thanks Given: 6
Thanks Rcvd at 16 Times in 10 Posts
runio Reputation: 0
https://en.wikipedia.org/wiki/Base36

Base34 is (0-9), (A-X)

Example code converted from Base36
Code:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

static char *base34enc(long unsigned int value)
 {
	char base34[34] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWX";
	char buffer[14];
	unsigned int offset = sizeof(buffer);

	buffer[--offset] = '\0';
	do {
		buffer[--offset] = base34[value % 34];
	} while (value /= 34);

	  return strdup(&buffer[offset]); 
  }

static long unsigned int base34dec(const char *text)
{
    return strtoul(text, NULL, 34);
}

int main()
{
    printf("The number(unsigned long integer) is %lu\n", base34dec("ABCDEF"));
    return 0;
}
Reply With Quote
  #3  
Old 03-13-2020, 03:02
TempoMat TempoMat is offline
Friend
 
Join Date: Jan 2006
Posts: 89
Rept. Given: 10
Rept. Rcvd 6 Times in 6 Posts
Thanks Given: 4
Thanks Rcvd at 28 Times in 21 Posts
TempoMat Reputation: 6
@runio

If I am not mistaken the unsigned long integer type should be in the range [0, +18,446,744,073,709,551,615].
Therefore the code snippet will not work for a number like B9DDE784B6FFC653DFEC3E94D6B610 (965075674130144583043497186064512528) or larger.

Regards
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Strange string encoding in C code dila Source Code 10 04-10-2018 03:45
Code timing snippet Git Developer Section 5 01-05-2018 02:05
Any ideas about executing phpinfo() in this code snippet XnHandt General Discussion 0 12-28-2012 00:46
How to execute a snippet of code before the main execution! Android General Discussion 8 10-04-2006 01:22


All times are GMT +8. The time now is 07:52.


Always Your Best Friend: Aaron, JMI, ahmadmansoor, ZeNiX, chessgod101
( Since 1998 )