|
It is an array BYTE data[212 Byte], i would like to chanage the hex values saved in the array to int values, as i should decode the polar coordinates from the Hex values saved in the data array.
|
|
|
|
|
if it is an array of bytes, then you don't need to "convert", you only need to copy, because as i said in my previous post, hexadecimal is only a representation of the binary in memory...
|
|
|
|
|
v2.0 wrote: if you have 32 apples, it is the same as having 0x20 apples...
It reminds me of another discussion[^]
|
|
|
|
|
Cedric Moonen wrote: It reminds me of another discussion[^]
exactly... i wanted to link the post, but couldn't find it...
the comparison still deserves '5'
|
|
|
|
|
Ya i got it guys....actually am alramed, i would like to convert the Hex to decimal value
|
|
|
|
|
chaitanya22 wrote: Ya i got it guys
Nope you didn't get it, otherwise you would not have asked again. What do you want to do EXACTLY ? And don't answer 'converting hex to decimal value' because this is totally nonsense ! Again, I will express it another way: it's like asking "I have 7 apples, I want to convert these apples in hexadecimal". Mmmmh, sounds, err, how to say....special, isn't ?
This is the same for your question.
So, formulate your question precisely. What do you want to do ? Convert a string representing a number ?
|
|
|
|
|
I would like to convert Hex number i,e 40 or 0x0C or 0x04B to binary value or decimal value.
|
|
|
|
|
|
The function I think you're looking for is strtol() declared in <stdlib.h>.
strtol() takes a string and converts it into a long.
You'll find more info about it here[^].
Hope this helps
--
Roger
It's supposed to be hard, otherwise anybody could do it!
|
|
|
|
|
would that function convert Hex number to binary value?
for eg:0x65=1100101,, i would like to ahve so...
|
|
|
|
|
Even with the explanation of the apples you still don't get it. In other tearms: hex numbers and decimal numbers doesn't exist (it's a bad use of the language). Instead you should say hexadecimal REPRESENTATION or binary REPRESENTATION of a number.
Let's take an example:
int BinValue = 0b1100101;
int HexValue = 0x65;
int DecValue = 101;
In this example, all three numbers are exactly the same and if you compare them, the result will be true.
Hope it is clear now.
|
|
|
|
|
Do you mean a string in hexadecimal format? You can do such a conversion with strtol. If you set the last parameter to 0 it does even automatically detect the number base depending on the first characters, e.g. if you have a string like 0xFF it will be converted to the integer value 255.
Here is an example code:
<br />
const char* szNumber = "0x1234";<br />
char* pHelp;<br />
<br />
int nNumber = strtol(szNumber, &pHelp, 0);
Regards
Konrad
|
|
|
|
|
Hi
friends
I have a structure declared like this
typedef unsigned char byte;
typedef struct date
{
short year;
byte month;
byte day;
}date_t;
and a function
void function(date_t t)
{
}
here I want to set some default value to this argument "date_t t' say NULL.
void function(date_t t=NULL)
{
}
How I can do that?
|
|
|
|
|
void function(date_t t = {0, 0, 0}) {
}
|
|
|
|
|
|
getting any error from the compiler ?
|
|
|
|
|
Add some constructors:
struct date_t
{
date_t()
{
}
date_t(short y, byte m, byte d): year(y), month(m), day(d)
{}
short year;
byte month;
byte day;
};
Now you can use it as follows:
date_t d1 = date_t(2006, 1, 1);
date_t d2 = date_t();
void function(date_t t = date_t())
{
}
Steve
|
|
|
|
|
well my limitation is I can not modify the date_t structure code.
|
|
|
|
|
so why not creating two overloads of the function ? one with no parameters, the other getting a date_t ?
moreover, even without changing the date_t structure, using function(date_t t = date_t()) { } should work if the structure don't define any constructor (the compiler defines one by default).
|
|
|
|
|
Hello v2.0,
Is the fact that the default constructor sets all struct field values to 0 a C++ Standard or is it compiler-dependent ?
Thanks, v2.0,
Bio.
|
|
|
|
|
in C++, structures are actually classes.
when a compiler (whatever the plateform) sees no constructor defined in a class, it creates implicitely an empty one for that class...
there, i cannot be sure that the fields will be filled with 0, but i think so.
to be verified.
|
|
|
|
|
You could derive from it:
struct my_date_type : date_t
{
my_date_type()
{
}
my_date_type(short y, byte m, byte d): year(y), month(m), day(d)
{}
};
Now you can use it as follows:
my_date_type d1 = my_date_type(2006, 1, 1);
my_date_type d2 = my_date_type();
void function(my_date_type t = my_date_type())
{
}
Steve
|
|
|
|
|
You can do like this...
date_t t = {12,12,12};
<font color=blue>void</font> function(date_t arg = t);
....
<font color=blue>void</font> function(date_t arg)
{
....
}
Nibu thomas
Software Developer
|
|
|
|
|
I think this is probably the best technique so far.
Steve
|
|
|
|
|
i have to gif image on picture box if anybody know please give me answer ASAP
Bankey Khandelwal
Software Engineer
|
|
|
|