PostGIS  2.3.8dev-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 652 of file lwgeom_api.c.

Referenced by rt_raster_from_hexwkb().

653 {
654  /* do this a little brute force to make it faster */
655 
656  uint8_t result_high = 0;
657  uint8_t result_low = 0;
658 
659  switch (str[0])
660  {
661  case '0' :
662  result_high = 0;
663  break;
664  case '1' :
665  result_high = 1;
666  break;
667  case '2' :
668  result_high = 2;
669  break;
670  case '3' :
671  result_high = 3;
672  break;
673  case '4' :
674  result_high = 4;
675  break;
676  case '5' :
677  result_high = 5;
678  break;
679  case '6' :
680  result_high = 6;
681  break;
682  case '7' :
683  result_high = 7;
684  break;
685  case '8' :
686  result_high = 8;
687  break;
688  case '9' :
689  result_high = 9;
690  break;
691  case 'A' :
692  case 'a' :
693  result_high = 10;
694  break;
695  case 'B' :
696  case 'b' :
697  result_high = 11;
698  break;
699  case 'C' :
700  case 'c' :
701  result_high = 12;
702  break;
703  case 'D' :
704  case 'd' :
705  result_high = 13;
706  break;
707  case 'E' :
708  case 'e' :
709  result_high = 14;
710  break;
711  case 'F' :
712  case 'f' :
713  result_high = 15;
714  break;
715  }
716  switch (str[1])
717  {
718  case '0' :
719  result_low = 0;
720  break;
721  case '1' :
722  result_low = 1;
723  break;
724  case '2' :
725  result_low = 2;
726  break;
727  case '3' :
728  result_low = 3;
729  break;
730  case '4' :
731  result_low = 4;
732  break;
733  case '5' :
734  result_low = 5;
735  break;
736  case '6' :
737  result_low = 6;
738  break;
739  case '7' :
740  result_low = 7;
741  break;
742  case '8' :
743  result_low = 8;
744  break;
745  case '9' :
746  result_low = 9;
747  break;
748  case 'A' :
749  case 'a' :
750  result_low = 10;
751  break;
752  case 'B' :
753  case 'b' :
754  result_low = 11;
755  break;
756  case 'C' :
757  case 'c' :
758  result_low = 12;
759  break;
760  case 'D' :
761  case 'd' :
762  result_low = 13;
763  break;
764  case 'E' :
765  case 'e' :
766  result_low = 14;
767  break;
768  case 'F' :
769  case 'f' :
770  result_low = 15;
771  break;
772  }
773  return (uint8_t) ((result_high<<4) + result_low);
774 }
Here is the caller graph for this function: