Converting string of 1s and 0s into binary value

前端 未结 6 936
梦如初夏
梦如初夏 2020-11-27 07:06

I\'m trying to convert an incoming sting of 1s and 0s from stdin into their respective binary values (where a string such as \"11110111\" would be converted to 0xF7). This s

6条回答
  •  情话喂你
    2020-11-27 08:06

    You can use strtol

    char string[] = "1101110100110100100000";
    char * end;
    long int value = strtol (string,&end,2);
    

提交回复
热议问题