• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2476
  • Last Modified:

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
0
yc_yc
Asked:
yc_yc
  • 2
  • 2
  • 2
  • +1
1 Solution
 
ozoCommented:
In ASCII, 0x30 = '0'
0
 
ozoCommented:
> str==mon[i]
I think you may have meant strcmp(str,mon[i])==0
0
 
Jaime OlivaresSoftware 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
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
yc_ycAuthor 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
 
Infinity08Commented:
>> 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
 
yc_ycAuthor 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
 
Infinity08Commented:
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

Featured Post

Simplify Active Directory Administration

Administration of Active Directory does not have to be hard.  Too often what should be a simple task is made more difficult than it needs to be.The solution?  Hyena from SystemTools Software.  With ease-of-use as well as powerful importing and bulk updating capabilities.

  • 2
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now