Given For e.g,
char input[] = "10011210582553796";
now Hexadecimal of 10011210582553796 is 2391249A8B74C4.
So output unsigned char* should have value,
unsigned char output[8] = {0x00,0x23,0x91,0x24,0x9A,0x8B,0x74,0xC4};
Any solution to convert given input char* to output char* with above mentioned requirement?
code should run on platform for which __int64/signed long long is not supported.
Thanx in advance...
any solution to convert given char*(number) to required unsi
Moderator: Community Moderators
-
- Posts: 2
- Joined: Sun Jul 06, 2008 2:35 pm
- heebyjeebys
- Posts: 1352
- Joined: Thu Feb 28, 2008 10:24 pm
Re: any solution to convert given char*(number) to required unsi
right this is converting to hex with c#passionpatel wrote:Given For e.g,
char input[] = "10011210582553796";
now Hexadecimal of 10011210582553796 is 2391249A8B74C4.
So output unsigned char* should have value,
unsigned char output[8] = {0x00,0x23,0x91,0x24,0x9A,0x8B,0x74,0xC4};
Any solution to convert given input char* to output char* with above mentioned requirement?
code should run on platform for which __int64/signed long long is not supported.
Thanx in advance...
Code: Select all
// Store integer 182
int decValue = 182;
// Convert integer 182 as a hex in a string variable
string hexValue = decValue.ToString("X");
// Convert the hex string back to the number
int decAgain = int.Parse(hexValue, System.Globalization.NumberStyles.HexNumber);
Code: Select all
label1.text = hex$(input.text).Convert.ToString()
for c++
Code: Select all
#include <stdio.h>
#include <stdlib.h>
/*
* To convert 53 to the character 'S':
* char returnVal = hexToString('5', '3');
*/
char hexToAscii(char first, char second)
{
char hex[5], *stop;
hex[0] = '0';
hex[1] = 'x';
hex[2] = first;
hex[3] = second;
hex[4] = 0;
return strtol(hex, &stop, 16);
}
int main(int argc, char* argv[])
{
printf("%c\n", hexToAscii('5', '3'));
}
Code: Select all
Print HEX$({value})
Code: Select all
input "How many numbers ";n
dim$ values (n)
result$ = ""
for i = 1 to n
print "Value "; i ;
input value(i)
next
input "Save, print or display hex values [s,p,d]";r$
if r$ = "s" then goto save
if r$ = "p" then goto print
if r$ = "d" then goto display
else end
save:
open o,#2,"result.txt"
for i = 1 to n
print #2, hex$(value (i))
next i
close #2
end
print:
for i = 1 to n
lprint hex$(value(i))
next
end
display:
for i = to n
print hex$(value(i))
next
end
Heeby's here! 

-
- Posts: 2
- Joined: Sun Jul 06, 2008 2:35 pm
Re: any solution to convert given char*(number) to required unsi
found solution
int number = 0;
char numberchars[] = "10011210582553796";
int i = 0;
int ans = 0;
int carry = 0;
char answerArray[100] = {0};
char remainderArray[100] = {0};
int remindex = 0;
int ansindex = 0;
int remainder = 0;
while( numberchars != '\0' )
{
while( numberchars != '\0' )
{
char currentchar[2] = {0};
currentchar[0]=numberchars;
int num = atoi(currentchar);
num += remainder;
remainder = 0;
if ( num < 2 )
{
remainder = num;
if(i>0)
answerArray[ansindex++] = '0';
}
else
{
remainder = num % 2;
int answer = num / 2;
char a[2] = {0};
itoa(answer,a,10);
answerArray[ansindex++] = a[0];
}
i++;
remainder *= 10;
}
char a[2] = {0};
int rval = remainder / 10;
itoa(remainder / 10,a,10);
remainderArray[remindex++] = a[0];
int size = sizeof(answerArray);
memcpy(numberchars,answerArray,sizeof(answerArray));
size = sizeof(answerArray);
memset(answerArray,0,sizeof(answerArray));
ansindex = 0;
remainder = 0;
i=0;
}
char int64[8] = {0};
for(int k=0;remainderArray[k]!= '\0';k++)
{
int64[7-(k/8)] |= ((remainderArray[k]-'0') << (k%8));
}
int number = 0;
char numberchars[] = "10011210582553796";
int i = 0;
int ans = 0;
int carry = 0;
char answerArray[100] = {0};
char remainderArray[100] = {0};
int remindex = 0;
int ansindex = 0;
int remainder = 0;
while( numberchars != '\0' )
{
while( numberchars != '\0' )
{
char currentchar[2] = {0};
currentchar[0]=numberchars;
int num = atoi(currentchar);
num += remainder;
remainder = 0;
if ( num < 2 )
{
remainder = num;
if(i>0)
answerArray[ansindex++] = '0';
}
else
{
remainder = num % 2;
int answer = num / 2;
char a[2] = {0};
itoa(answer,a,10);
answerArray[ansindex++] = a[0];
}
i++;
remainder *= 10;
}
char a[2] = {0};
int rval = remainder / 10;
itoa(remainder / 10,a,10);
remainderArray[remindex++] = a[0];
int size = sizeof(answerArray);
memcpy(numberchars,answerArray,sizeof(answerArray));
size = sizeof(answerArray);
memset(answerArray,0,sizeof(answerArray));
ansindex = 0;
remainder = 0;
i=0;
}
char int64[8] = {0};
for(int k=0;remainderArray[k]!= '\0';k++)
{
int64[7-(k/8)] |= ((remainderArray[k]-'0') << (k%8));
}