15,885,216 members
Home / Discussions / C / C++ / MFC

# C / C++ / MFC

 Re: [edited]Re: pointers to functions Calin Negru16-Jul-22 6:57 Calin Negru 16-Jul-22 6:57
 Re: [edited]Re: pointers to functions Richard MacCutchan16-Jul-22 20:58 Richard MacCutchan 16-Jul-22 20:58
 Re: pointers to functions Greg Utas16-Jul-22 7:36 Greg Utas 16-Jul-22 7:36
 Convert decimal to binary in C sahil Ranka14-Jul-22 1:14 sahil Ranka 14-Jul-22 1:14
 Re: Convert decimal to binary in C Mircea Neacsu14-Jul-22 1:25 Mircea Neacsu 14-Jul-22 1:25
 Re: Convert decimal to binary in C Richard MacCutchan14-Jul-22 1:29 Richard MacCutchan 14-Jul-22 1:29
 Re: Convert decimal to binary in C sahil Ranka14-Jul-22 2:42 sahil Ranka 14-Jul-22 2:42
 Re: Convert decimal to binary in C CPallini14-Jul-22 2:36 CPallini 14-Jul-22 2: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 2:42 sahil Ranka 14-Jul-22 2:42
 Re: Convert decimal to binary in C CPallini14-Jul-22 3:14 CPallini 14-Jul-22 3:14
 Re: Convert decimal to binary in C Richard MacCutchan14-Jul-22 21:15 Richard MacCutchan 14-Jul-22 21:15
 Prey/predator c++ project sahil Ranka12-Jul-22 0:26 sahil Ranka 12-Jul-22 0:26
 Re: Prey/predator c++ project Richard MacCutchan12-Jul-22 0:29 Richard MacCutchan 12-Jul-22 0:29
 Re: Prey/predator c++ project Greg Utas12-Jul-22 1:20 Greg Utas 12-Jul-22 1:20
 How to share a pointer between an EXE and a DLL Mircea Neacsu11-Jul-22 13:50 Mircea Neacsu 11-Jul-22 13:50
 Re: How to share a pointer between an EXE and a DLL CPallini11-Jul-22 20:12 CPallini 11-Jul-22 20:12
 Re: How to share a pointer between an EXE and a DLL Mircea Neacsu12-Jul-22 4:01 Mircea Neacsu 12-Jul-22 4:01
 Re: How to share a pointer between an EXE and a DLL Victor Nijegorodov12-Jul-22 6:22 Victor Nijegorodov 12-Jul-22 6:22
 Re: How to share a pointer between an EXE and a DLL Mircea Neacsu12-Jul-22 7:52 Mircea Neacsu 12-Jul-22 7:52
 Re: How to share a pointer between an EXE and a DLL Victor Nijegorodov12-Jul-22 8:04 Victor Nijegorodov 12-Jul-22 8:04
 Re: How to share a pointer between an EXE and a DLL JudyL_MD12-Jul-22 11:31 JudyL_MD 12-Jul-22 11:31
 Re: How to share a pointer between an EXE and a DLL Mircea Neacsu12-Jul-22 12:17 Mircea Neacsu 12-Jul-22 12:17
 Re: How to share a pointer between an EXE and a DLL JudyL_MD12-Jul-22 13:29 JudyL_MD 12-Jul-22 13:29
 Re: How to share a pointer between an EXE and a DLL Graham Breach11-Jul-22 20:30 Graham Breach 11-Jul-22 20:30
 Re: How to share a pointer between an EXE and a DLL Gerry Schmitz12-Jul-22 6:57 Gerry Schmitz 12-Jul-22 6:57
 Last Visit: 31-Dec-99 18:00     Last Update: 24-Apr-24 12:50 Refresh ᐊ Prev1...65666768697071727374 Next ᐅ