Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Learning assembly

Status
Not open for further replies.

rjwilldohisbest

Technical User
Jun 2, 2001
79
0
0
US
Hello

I have the art of assembly tutorial and another one and I appear to be having trouble with converting binary into decimal.

Here's an example of what I mean:
**********************************************************
BIN to DEC coversions self exercises


BIN: 11001
This one from the tutorial and comes out to be correct:
1*2^0 + 1*2^1 + 0*2^2 + 0*2^3 + 1*2^4

= 1 + 2 + 0 + 0 + 16 //--> 19 DEC

*******************************************************************
These answers should be flip-flopped
41 should be the first example and 37 should be the second example?

BIN: 101001

1*2^0 + 0*2^1 + 1*2^2 + 0*2^3 + 0*2^4 + 1*2^5

= 1 + 0 + 4 + 0 + 0 + 32 //--> 37 DEC


100101

1*2^0 + 0*2^1 + 0*2^2 + 1*2^3 + 0*2^4 + 1*2^5

= 1 + 0 + 0 + 8 + 0 + 32 //--> 41 DEC

********************************************************************
One I tried out on my own.
Another one that comes out wrong. Should be 78, not 57?
BIN: 1001110

1*2^0 + 0*2^1 + 0*2^2 + 1*2^3 + 1*2^4 + 1*2^5 + 0*2^6

= 1 + 0 + 0 + 8 + 16 + 32 + 0 //--> 57 DEC



I do not know what I may be doing wrong. I do examples on paper and they come out different, but the example from the tutorial comes out right. I am a total beginner at this and if anyone knows what I might be doing wrong, please let me know.

Thanks for your time.

RJ
 
How do you split up a decimal number? From high significance to low significance!
e.g.: 1324 = 1*1000 + 3*100 + 2*10 + 4*1

How do you split up a binary number? Also from high significance to low significance!
e.g.: 11001 = 1*16 + 1*8 + 0*4 + 0*2 + 1*1

What does high and low significance mean? A digit is high significant if the value of a number changes relatively much when making small changes to this digit.
e.g.: take 43816, add 1 to MSD (most significant digit), then we get 53816, which has a much bigger value than 43816 (we added 10000 to the number, just by adding 1 to the MSD!).
The LSD (least significant digit) is then of course the rightmost digit.

The only difference between binary and decimal is that you use another base number, 2 in stead of 10, and this has two consequences:
1) you can only use 2 different digits (people have chosen this to be zero and one) in stead of 10.
2) you must define values on the base of powers of 2 in stead of powers of 10
e.g.: 1101d = 1*1000 + 1*100 + 0*10 + 1*1
1101b = 1*8 + 1*4 + 0*2 + 1*1 Regards,
Bert Vingerhoets
vingerhoetsbert@hotmail.com
Don't worry what people think about you. They're too busy wondering what you think about them.
 
Hi Bert

This explaination simplifies things better as the base 2 and ten systems goes, now -- the 11001 part, how is this converted to a decimal equivalent?

11001 = 1*16 + 1*8 + 0*4 + 0*2 + 1*1

The way you show this looks easier to comprehend than how the tutorial I'm learning explains it.

The tutorial had a way of adding these somehow together to form a decimal equivalent. The first example I displayed was considered correct, the others after that aren't for some reason.

I read that going in the other direction i.e. converting decimal to binary -- you need to keep dividing from the full decimal number by 2's and if there is no remainder then that number becomes a O and if the number doesn't divide equally it somehow becomes a 1? This division keeps going until there is nothing left of the decimal number and what is leftover is the binary string. I think this is right?

maybe the tutorial I'm learning is explaining it differently but is the same thing, or maybe I need a different tutorial?

Thanks for your time. The layout you showed looks better to me and looks much simpler.

RJ



 
bin->dec:
each position of a binary digit corresponds to a value that can be interpreted as a decimal value, if the digit is a 1, this means that the value at that position is part of the result (i.e. must be added to the result).
Example:
Code:
positions:    8    7    6    5    4    3    2    1
dec value:  128   64   32   16    8    4    2    1
pwr of 2 :  2^7  2^6  2^5  2^4  2^3  2^2  2^1  2^0

              0    0    0    1    1    0    0    1
            = 0  + 0  + 0 + 16  + 8  + 0  + 0  + 1
            = 25

dec->bin:
when converting a decimal value X to its corresponding binary value, you can use the following procedure:

substract the highest possible power of 2 from X
take a pencil and write 1
(*)if the second highest power of 2 is smaller than X, substract and write 1, else write 0
repeat from (*) to end until the power of 2 is 1

Example:
X = 25
highest power of 2, smaller than X = 16 (2^4)
X-16 = 9
bitstring = '1'
next power of 2 is 8 (2^3)
X >= 8?
yes -> X-8 = 1; bitstring = '11'
next power of 2 is 4 (2^2)
X >= 4?
no -> bitstring = '110'
next power of 2 is 2 (2^1)
X >= 2?
no -> bitstring = '1100'
next power of 2 is 1 (2^0)
X >= 1?
yes -> X-1 = 0; bitsring = '11001'
Regards,
Bert Vingerhoets
vingerhoetsbert@hotmail.com
Don't worry what people think about you. They're too busy wondering what you think about them.
 
Thanks Bert

Your examples are very easy to follow. I did a quiz exercises on one of those sites on math coversions and I passed it, was very surprised.

Thanks for your time Bert

RJ
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top