Click here to Skip to main content
15,917,174 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: converting from binary number representation to floating-point representation [modified] Pin
steve_o17-Mar-09 11:41
steve_o17-Mar-09 11:41 
GeneralRe: converting from binary number representation to floating-point representation Pin
CPallini17-Mar-09 11:55
mveCPallini17-Mar-09 11:55 
GeneralRe: converting from binary number representation to floating-point representation Pin
Stuart Dootson17-Mar-09 13:36
professionalStuart Dootson17-Mar-09 13:36 
GeneralRe: converting from binary number representation to floating-point representation [modified] Pin
steve_o17-Mar-09 17:07
steve_o17-Mar-09 17:07 
QuestionRe: converting from binary number representation to floating-point representation Pin
CPallini17-Mar-09 22:42
mveCPallini17-Mar-09 22:42 
GeneralRe: converting from binary number representation to floating-point representation Pin
Stuart Dootson17-Mar-09 23:12
professionalStuart Dootson17-Mar-09 23:12 
GeneralRe: converting from binary number representation to floating-point representation Pin
steve_o18-Mar-09 11:08
steve_o18-Mar-09 11:08 
GeneralRe: converting from binary number representation to floating-point representation Pin
Stuart Dootson18-Mar-09 14:11
professionalStuart Dootson18-Mar-09 14:11 
WIth 2's complement, all you need to do is assign the bools to the bits of a signed char - integers on virtually all (if not actually all) processors are represented in 2s complement.

With 1's complement, assign the bools to the bits of a signed char and invert the bits if the most significant bit is set:

void valueONESTWOS(bool input[], int n)
{
   const unsigned char raw = (input[0]?128 : 0) + (input[1]?64 : 0) + (input[2]?32 : 0) + (input[3]?16 : 0)
                             (input[4]?8 : 0) + (input[5]?4 : 0) + (input[6]?2 : 0) + (input[7]?1 : 0);
   const signed char twosComplement = raw;
   const signed char onesComplement = input[0]?(~raw):(raw);
   const bool onesComplementIsNegative = input[0];

   cout << "Twos complement = " << twosComplement << endl;
   cout << "Twos complement = " << (onesComplementIsNegative?'-':' ') << twosComplement << endl;
}


Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

QuestionChange Image in Excel Picture Object Pin
Sister Ray17-Mar-09 7:54
Sister Ray17-Mar-09 7:54 
QuestionWM_WINDOWPOSCHANING?? Pin
sam_psycho17-Mar-09 6:15
sam_psycho17-Mar-09 6:15 
AnswerRe: WM_WINDOWPOSCHANING?? Pin
Akt_4_U17-Mar-09 6:45
Akt_4_U17-Mar-09 6:45 
GeneralRe: WM_WINDOWPOSCHANING?? Pin
sam_psycho17-Mar-09 6:59
sam_psycho17-Mar-09 6:59 
GeneralRe: WM_WINDOWPOSCHANING?? Pin
David Crow17-Mar-09 9:04
David Crow17-Mar-09 9:04 
Questionwindows environment Pin
anassamar17-Mar-09 6:06
anassamar17-Mar-09 6:06 
AnswerRe: windows environment Pin
Code-o-mat17-Mar-09 6:13
Code-o-mat17-Mar-09 6:13 
QuestionRe: windows environment Pin
David Crow17-Mar-09 6:40
David Crow17-Mar-09 6:40 
AnswerRe: windows environment Pin
anassamar18-Mar-09 3:21
anassamar18-Mar-09 3:21 
GeneralRe: windows environment Pin
David Crow18-Mar-09 3:23
David Crow18-Mar-09 3:23 
AnswerRe: windows environment Pin
bulg17-Mar-09 6:58
bulg17-Mar-09 6:58 
QuestionUpdate CListCtrl Pin
durban217-Mar-09 4:17
durban217-Mar-09 4:17 
Questionbitwise Pin
mac_g17-Mar-09 3:57
mac_g17-Mar-09 3:57 
AnswerRe: bitwise Pin
David Crow17-Mar-09 4:07
David Crow17-Mar-09 4:07 
GeneralRe: bitwise Pin
mac_g17-Mar-09 4:10
mac_g17-Mar-09 4:10 
GeneralRe: bitwise Pin
mac_g17-Mar-09 4:58
mac_g17-Mar-09 4:58 
GeneralRe: bitwise Pin
bulg17-Mar-09 7:16
bulg17-Mar-09 7:16 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.