PostGIS  3.0.0dev-r@@SVN_REVISION@@

◆ parse_hex()

uint8_t parse_hex ( char *  str)

Convert a single hex digit into the corresponding char.

Convert a single hex digit into the corresponding char.

No error checking done!

Definition at line 516 of file lwgeom_api.c.

Referenced by rt_raster_from_hexwkb().

517 {
518  /* do this a little brute force to make it faster */
519 
520  uint8_t result_high = 0;
521  uint8_t result_low = 0;
522 
523  switch (str[0])
524  {
525  case '0' :
526  result_high = 0;
527  break;
528  case '1' :
529  result_high = 1;
530  break;
531  case '2' :
532  result_high = 2;
533  break;
534  case '3' :
535  result_high = 3;
536  break;
537  case '4' :
538  result_high = 4;
539  break;
540  case '5' :
541  result_high = 5;
542  break;
543  case '6' :
544  result_high = 6;
545  break;
546  case '7' :
547  result_high = 7;
548  break;
549  case '8' :
550  result_high = 8;
551  break;
552  case '9' :
553  result_high = 9;
554  break;
555  case 'A' :
556  case 'a' :
557  result_high = 10;
558  break;
559  case 'B' :
560  case 'b' :
561  result_high = 11;
562  break;
563  case 'C' :
564  case 'c' :
565  result_high = 12;
566  break;
567  case 'D' :
568  case 'd' :
569  result_high = 13;
570  break;
571  case 'E' :
572  case 'e' :
573  result_high = 14;
574  break;
575  case 'F' :
576  case 'f' :
577  result_high = 15;
578  break;
579  }
580  switch (str[1])
581  {
582  case '0' :
583  result_low = 0;
584  break;
585  case '1' :
586  result_low = 1;
587  break;
588  case '2' :
589  result_low = 2;
590  break;
591  case '3' :
592  result_low = 3;
593  break;
594  case '4' :
595  result_low = 4;
596  break;
597  case '5' :
598  result_low = 5;
599  break;
600  case '6' :
601  result_low = 6;
602  break;
603  case '7' :
604  result_low = 7;
605  break;
606  case '8' :
607  result_low = 8;
608  break;
609  case '9' :
610  result_low = 9;
611  break;
612  case 'A' :
613  case 'a' :
614  result_low = 10;
615  break;
616  case 'B' :
617  case 'b' :
618  result_low = 11;
619  break;
620  case 'C' :
621  case 'c' :
622  result_low = 12;
623  break;
624  case 'D' :
625  case 'd' :
626  result_low = 13;
627  break;
628  case 'E' :
629  case 'e' :
630  result_low = 14;
631  break;
632  case 'F' :
633  case 'f' :
634  result_low = 15;
635  break;
636  }
637  return (uint8_t) ((result_high<<4) + result_low);
638 }
unsigned char uint8_t
Definition: uthash.h:79
Here is the caller graph for this function: