a 0xFFFFFFFFFFFFFFFF should come as a negative number

Best Regards
Ashish Goel
"Think positive and find fuel in failure"
+919985813081
+919966006652


On Mon, Jan 16, 2012 at 8:19 AM, Gene <gene.ress...@gmail.com> wrote:

> Okay. Normally you want to use a library that someone else has
> tested.  So:
>
> sscanf("%x", &i);
>
> If you don't have access to any libraries, then:
>
> /*
>  * Return the integer value of the hex string s. Allowable characters
>  * are 0-9, a-f, A-F.  Any other character causes scanning to stop and
>  * the hex value of the string up to that character is returned. If
> the first
>  * character is non-hex, then zero is returned.
>  */
> int hex_to_int(char *s)
> {
>  int i = 0;
>  while (*s) {
>    if ('0' <= *s && *s <= '9')
>      i = (i << 4) + (*s - '0');
>    else if ('a' <= *s && *s <= 'f')
>      i = (i << 4) + *s + (10 - 'a');
>    else if ('A' <= *s && *s <= 'F')
>      i = (i << 4) + *s + (10 - 'A');
>    else break;
>    s++;
>  }
>  return i;
> }
>
> On Jan 15, 9:16 pm, Ashish Goel <ashg...@gmail.com> wrote:
> > i would assume C or C++
> >
> > Best Regards
> > Ashish Goel
> > "Think positive and find fuel in failure"
> > +919985813081
> > +919966006652
> >
> >
> >
> > On Mon, Jan 16, 2012 at 7:40 AM, Gene <gene.ress...@gmail.com> wrote:
> > > Which language?
> >
> > > On Jan 15, 8:23 pm, Ashish Goel <ashg...@gmail.com> wrote:
> > > > Hi,
> >
> > > > given a string in hex, convert it into int.
> > > > Write test cases for the same.
> >
> > > > Best Regards
> > > > Ashish Goel
> > > > "Think positive and find fuel in failure"
> > > > +919985813081
> > > > +919966006652
> >
> > > --
> > > You received this message because you are subscribed to the Google
> Groups
> > > "Algorithm Geeks" group.
> > > To post to this group, send email to algogeeks@googlegroups.com.
> > > To unsubscribe from this group, send email to
> > > algogeeks+unsubscr...@googlegroups.com.
> > > For more options, visit this group at
> > >http://groups.google.com/group/algogeeks?hl=en.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to