PostGIS  2.4.9dev-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 513 of file lwgeom_api.c.

Referenced by rt_raster_from_hexwkb().

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