sasano.c 609 Bytes
#include <ultra64.h>
#include <sasano.h>

void hex2bin(int mode,u64 inp,char* str){
  int i,j=0;
  u16 work16;
  u8 work8;

  switch (mode){
    case HEX2BIN_U16SPACE4BIT:
      work16=(u16)inp;

      for(i=0;i<16;i++){
        if (!(i%4) && i>0 ) str[j++]=' ';
        if (work16 >> 15) str[j++]='1';
        else str[j++]='0';
        work16 = work16 << 1;
      }
      break;
    case HEX2BIN_U8:
      work8=(u8)inp;

      for(i=0;i<8;i++){
        if (work8 >> 7) str[j++]='1';
        else str[j++]='0';
        work8 = work8 << 1;
      }
      break;
    default:
      break;
  }
  str[j]='\0';
}