15,792,330 members
Home / Discussions / C / C++ / MFC

# C / C++ / MFC

 Re: [edited]Re: pointers to functions Calin Negru16-Jul-22 7:57 Calin Negru 16-Jul-22 7:57
 Re: [edited]Re: pointers to functions Richard MacCutchan16-Jul-22 21:58 Richard MacCutchan 16-Jul-22 21:58
 Re: pointers to functions Greg Utas16-Jul-22 8:36 Greg Utas 16-Jul-22 8:36
 Convert decimal to binary in C sahil Ranka14-Jul-22 2:14 sahil Ranka 14-Jul-22 2:14
 Re: Convert decimal to binary in C Mircea Neacsu14-Jul-22 2:25 Mircea Neacsu 14-Jul-22 2:25
 Re: Convert decimal to binary in C Richard MacCutchan14-Jul-22 2:29 Richard MacCutchan 14-Jul-22 2:29
 Re: Convert decimal to binary in C sahil Ranka14-Jul-22 3:42 sahil Ranka 14-Jul-22 3:42
 Re: Convert decimal to binary in C CPallini14-Jul-22 3:36 CPallini 14-Jul-22 3:36
 As noted in other answers, your code handles at most four bits. Moreover, your function is assuming a (at least) 5-bytes buffer is provided by the caller. That's a flawn: the caller should provide the size of the buffer and the called should check if the size is big enough to produce the requested output. Try C ```#include #include #include bool uint2binstr(unsigned value, char output[], size_t output_size) { unsigned v = value; unsigned bits = 0; while ( v ) { v >>= 1; ++bits; } if ( ! bits ) ++bits; if ( output_size > bits ) { output[bits] = '\0'; while (bits) { --bits; output[bits] = (value & 1) + '0'; value >>= 1; } return true; } return false; } enum { N = 33 }; // assuming 'unsigned' is 32 bits int main() { char out[N]; unsigned a[] = { 0, 1, 128, 192, 65535, 65536, -1 }; for (size_t n=0; n
 Re: Convert decimal to binary in C sahil Ranka14-Jul-22 3:42 sahil Ranka 14-Jul-22 3:42
 Re: Convert decimal to binary in C CPallini14-Jul-22 4:14 CPallini 14-Jul-22 4:14
 Re: Convert decimal to binary in C Richard MacCutchan14-Jul-22 22:15 Richard MacCutchan 14-Jul-22 22:15
 Prey/predator c++ project sahil Ranka12-Jul-22 1:26 sahil Ranka 12-Jul-22 1:26
 Re: Prey/predator c++ project Richard MacCutchan12-Jul-22 1:29 Richard MacCutchan 12-Jul-22 1:29
 Re: Prey/predator c++ project Greg Utas12-Jul-22 2:20 Greg Utas 12-Jul-22 2:20
 How to share a pointer between an EXE and a DLL Mircea Neacsu11-Jul-22 14:50 Mircea Neacsu 11-Jul-22 14:50
 Re: How to share a pointer between an EXE and a DLL CPallini11-Jul-22 21:12 CPallini 11-Jul-22 21:12
 Re: How to share a pointer between an EXE and a DLL Mircea Neacsu12-Jul-22 5:01 Mircea Neacsu 12-Jul-22 5:01
 Re: How to share a pointer between an EXE and a DLL Victor Nijegorodov12-Jul-22 7:22 Victor Nijegorodov 12-Jul-22 7:22
 Re: How to share a pointer between an EXE and a DLL Mircea Neacsu12-Jul-22 8:52 Mircea Neacsu 12-Jul-22 8:52
 Re: How to share a pointer between an EXE and a DLL Victor Nijegorodov12-Jul-22 9:04 Victor Nijegorodov 12-Jul-22 9:04
 Re: How to share a pointer between an EXE and a DLL JudyL_MD12-Jul-22 12:31 JudyL_MD 12-Jul-22 12:31
 Re: How to share a pointer between an EXE and a DLL Mircea Neacsu12-Jul-22 13:17 Mircea Neacsu 12-Jul-22 13:17
 Re: How to share a pointer between an EXE and a DLL JudyL_MD12-Jul-22 14:29 JudyL_MD 12-Jul-22 14:29
 Re: How to share a pointer between an EXE and a DLL Graham Breach11-Jul-22 21:30 Graham Breach 11-Jul-22 21:30
 Re: How to share a pointer between an EXE and a DLL Gerry Schmitz12-Jul-22 7:57 Gerry Schmitz 12-Jul-22 7:57
 Last Visit: 31-Dec-99 19:00     Last Update: 1-Dec-23 7:05 Refresh ᐊ Prev1...47484950515253545556 Next ᐅ