• C

hexidecimal 0x30

Following piece of code character array B try to get date DDMMYYYY from character arrary A.
Can someone explain what the "0x30" does and how the statements (a), (b) function?

m = 30;
n = 0;
charB[n++] = charA[m++] - 0x30;
charB[n++] = charA[m++] - 0x30;

m++;
str[0] = charA[m++];
str[1] = charA[m++];
str[2] = charA[m++];
str[3] = 0;
for (i=0; i<12; i++)
{
if (str==mon[i])
break;
}
i++;
charB[n++] = i/10;      (a)
charB[n++] = i-i/10;      (b)

m++;
charB[n++] = charA[m++] - 0x30;
charB[n++] = charA[m++] - 0x30;
charB[n++] = charA[m++] - 0x30;
charB[n++] = charA[m++] - 0x30;

str[] is array of character and mon[] is array of string storing "Jan", "Feb", ...

Thanks
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Commented:
In ASCII, 0x30 = '0'
0
Commented:
> str==mon[i]
I think you may have meant strcmp(str,mon[i])==0
0
Software ArchitectCommented:
notice the 0x30 (or 48 decimal) is the ASCII value of the zero digit, as stated by ozo. It is used in the code you provided to convert an ASCII digit into an integral value. By example '5' has an ascii code 53 decimal, if we substract 48 (0x30) from it, we have 5.
0

Experts Exchange Solution brought to you by

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Author Commented:
Thanks for your reply. I still didn't understand the statements (a) & (b) in that piece of code.
It seems used to get month info, but how to explain i/10 & i-i/10 stand for month (MM)?

m++;
str[0] = charA[m++];
str[1] = charA[m++];
str[2] = charA[m++];
str[3] = 0;
for (i=0; i<12; i++)
{
if (str==mon[i])
break;
}
i++;
charB[n++] = i/10;        (a)
charB[n++] = i-i/10;      (b)

str[] is array of character and mon[] is array of string storing "Jan", "Feb", ...

0
Commented:
>> I still didn't understand the statements (a) & (b)

/ is the division operator, so i / 10 is the result of dividing i by 10, and then rounded down to the nearest int. For example, for i = 35, i / 10 will be 3.

i - i / 10 is the same as (i - (i / 10)), so the result of dividing i by 10 (see previous paragraph) is subtracted from i.

>> but how to explain i/10 & i-i/10 stand for month (MM)?

It doesn't. There's something wrong with that code. They might have meant :

charB[n++] = i / 10;        /*(a)*/
charB[n++] = i % 10;      /*(b)*/

But that could have been done more easy using sprintf for example.

This whole code is pretty messy, and does things way more complicated than they need to be. Can you explain what you are trying to do ?
0
Author Commented:
Is there any way I still can give some points to Infinity08? I think his answer is right original  two statements might be something wrong. Thanks again.
0
Commented:
You can get this question re-opened by posting a 0-point question in the Community Support zone :

http://www.experts-exchange.com/Other/Community_Support/
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C

From novice to tech pro — start learning today.