PostGIS  2.5.1dev-r@@SVN_REVISION@@

◆ parse_hex()

uint8_t parse_hex ( char *  str)

Given a string with at least 2 chars in it, convert them to a byte value.

Convert a single hex digit into the corresponding char.

No error checking done!

Definition at line 537 of file lwgeom_api.c.

Referenced by rt_raster_from_hexwkb().

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