/*
   This subroutine converts a string from bin to decimal. If there is an
   invalid Hexnumber in the string, then the subroutine will return -1
*/

#include <stdio.h>
#include "xasm.h"

int atob( char *str )
{
WORD val = 0; /* Resulting Value */
BYTE valid = 0;
	
while ( *str == ' ' && *str != 0 && *str != '\n' )
   str++;

while ( *str >= '0' && *str <= '1')
   {
   valid = 1;
   val = (val * 2) + (*str & 0xff) - 0x30;
   str++;
   }

if ( valid && (*str == '\n' || *str == 0 || *str == ' ') )
   return ( (int) val ); /* Good Value */
 else
   {
   xerror( "atoh: Conversion Error" );
   return ( -1 ); /* Bad Value */
   }
}
