Re: [algogeeks] how to convert a floating point number into binary representation.

2012-01-27 Thread Dheeraj Sharma
you can use concept of union to display floating in binary union x { float z; int a; }; set the value of z..and represent it by "a" assuming int and float have same size On Mon, Jan 23, 2012 at 8:42 AM, Ashish Goel wrote: > > > string ftob(string s) > { > int intPart= Integer.parseInt(s.s

Re: [algogeeks] how to convert a floating point number into binary representation.

2012-01-22 Thread Ashish Goel
string ftob(string s) { int intPart= Integer.parseInt(s.substring(0, s.indexOf('.'))); double fraction = Double.parseDouble(s.substring( s.indexOf('.'), s.length())); string intString=""; while (intPart) { int bit=intPart&1; intPart >>=1; intString = bit + intString; } string fracString = "

Re: [algogeeks] how to convert a floating point number into binary representation.

2012-01-21 Thread Arun Vishwanathan
@immanuel: in this part while (decimalPart > 0 && decimalPart < 1 && str.length < 64) { decimalPart *= 2; str[str.length] = (decimalPart - 0) + '0'; } is this decimalPart-0 correct here? if decimalpart (say) starts as 0.584 then after doing that into 2 we 1.164. What happe

Re: [algogeeks] how to convert a floating point number into binary representation.

2011-05-24 Thread immanuel kingston
correct me if I am wrong. String convertFloatToBinary(float num) { String str = ""; int numBeforeDecimal = (int)num; float decimalPart = num - (float)numBeforeDecimal; int sign=1; if (numBeforeDecimal < 0 ) sign = -1; if (sign < 0) str[str.length] = '-';

Re: [algogeeks] how to convert a floating point number into binary representation.

2011-05-23 Thread Naveen Kumar
http://kipirvine.com/asm/workbook/floating_tut.htm On Tue, May 24, 2011 at 12:09 PM, saurabh agrawal wrote: > > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To post to this group, send email to algogeeks@googlegroups.com. > To unsub

[algogeeks] how to convert a floating point number into binary representation.

2011-05-23 Thread saurabh agrawal
-- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at ht