QUOTE(andre03 @ 5 Oct, 2008 - 06:02 PM)

convert a 32 bit binary number to a decimal number
PLEASE HELP !!!!!!!!
Here is one way ... done in HLA ...
CODE
program bitStrToDec2;
#include( "stdlib.hhf" )
static
s1: string:= "00001111000011110000111100001111";
s2: string:= "11110000111100001111000011110000";
s3: string:= "01111111111111111111111111111111";
s4: string:= "11111111111111111111111111111111";
// Returns the decimal value of bit string 's' in the EAX register ...
#macro my_bitStrToDec( s );
push( ebx );
push( ecx );
push( edx );
mov( 0, eax );
mov( s, ebx ); // get address of the first char of s into eax register ...
mov( 1, edx );
for( mov( 31, ecx ); (type int32 ecx) > 0; dec(ecx) ) do
if( (type char [ebx+ecx]) == '1' ) then
or( edx, eax );
endif;
shl( 1, edx );
endfor;
if( (type char [ebx+ecx]) == '1' ) then
or( edx, eax );
endif;
pop( edx );
pop( ecx );
pop( ebx );
#endmacro
begin bitStrToDec2;
// handle first evaluation ...
my_bitStrToDec( s1 );
stdout.put( "The 32 'bits' in string ", s1, " = ", (type uns32 eax), " decimal.", nl );
// handle 2nd evaluation ...
my_bitStrToDec( s2 );
stdout.put( "The 32 'bits' in string ", s2, " = ", (type uns32 eax), " decimal.", nl );
// handle 3rd evaluation ...
my_bitStrToDec( s3 );
stdout.put( "The 32 'bits' in string ", s3, " = ", (type uns32 eax), " decimal.", nl );
// handle 4th evaluation ...
my_bitStrToDec( s4 );
stdout.put( "The 32 'bits' in string ", s4, " = ", (type uns32 eax), " decimal.", nl );
stdout.put( "Press 'Enter' key to continue ... " );
stdin.readLn();
end bitStrToDec2;
Or here is an other slightly different way ... also in HLA (high level assembly) ...
CODE
program bitStrToDec;
#include( "stdlib.hhf" )
static
s1: string:= "00001111000011110000111100001111";
s2: string:= "11110000111100001111000011110000";
s3: string:= "01111111111111111111111111111111";
s4: string:= "11111111111111111111111111111111";
// Returns the decimal value of bit string 's' in the EAX register ...
#macro my_bitStrToDec( s );
push( ebx );
push( ecx );
mov( 0, eax );
mov( s, ebx ); // get address of the first char of s into eax register ...
for( mov( 0, ecx ); ecx < 31; inc(ecx) ) do
if( (type char [ebx+ecx]) == '1' ) then
add( 1, eax );
endif;
shl( 1,eax );
endfor;
if( (type char [ebx+ecx]) == '1' ) then
add( 1, eax );
endif;
pop( ecx );
pop( ebx );
#endmacro
begin bitStrToDec;
// handle first evaluation ...
my_bitStrToDec( s1 );
stdout.put( "The 32 'bits' in string ", s1, " = ", (type uns32 eax), " decimal.", nl );
// handle 2nd evaluation ...
my_bitStrToDec( s2 );
stdout.put( "The 32 'bits' in string ", s2, " = ", (type uns32 eax), " decimal.", nl );
// handle 3rd evaluation ...
my_bitStrToDec( s3 );
stdout.put( "The 32 'bits' in string ", s3, " = ", (type uns32 eax), " decimal.", nl );
// handle 4th evaluation ...
my_bitStrToDec( s4 );
stdout.put( "The 32 'bits' in string ", s4, " = ", (type uns32 eax), " decimal.", nl );
stdout.put( "Press 'Enter' key to continue ... " );
stdin.readLn();
end bitStrToDec;
This post has been edited by David W: 5 Oct, 2008 - 08:47 PM