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...
right this is converting to hex with c#
- 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);
for VB
- Code: Select all
label1.text = hex$(input.text).Convert.ToString()
i shortend that, orginal page is :
http://www.vb-helper.com/howto_dec_hex_oct_bin.htmlfor 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'));
}
if you want to use the original basic, then just use:
- Code: Select all
Print HEX$({value})
syntax. But it does it number by number so you will need a for/next loop:
- 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
if theres anyproblem with the BASIC one, i'm sorry. I havn't done basic for quite a while. Thats a (should be) fully working program there (i just wrote that on the spot), provided that you use quick basic