Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Simple Maths questions? and binary addition/subtraction?

Status
Not open for further replies.

fouadalnoor

Member
Hello guys,

I know this is really silly but I am a little confused about how to do the following operation by hand:

0.25-0.5? or any similar questions:eek:

Also, when it comes to fixed point signed numbers, how do you subtract them?

Say I choose my MSB to be the sign and the 7th bit in an 8 bit number to be 1, while bits 6-0 are the fractional part as shown below:

[SIGN][2^0][2^-1][2^-2][2^-3][2^-4][2^-5][2^-6]

So for example: 01.100000 is 1.5 in decimal.

When aligning the decimal point its easy to add say 1+0.25:

01.000000
+00.010000
=01.010000 = 1.25 in decimal

But how would I do 1-0.25?

Hope you can help!
 
01000000
-00010000
=
00110000 = 0.5 + 0.25 = 0.75
rules:
1-0 = 1
1-1=0
0-1 = 1 with a borrow (all zeros upstream become 1 until first 1 hit which becomes 0), if there are no ones upstream, the overflow flag is set (overflow/borrow).
 
01000000
-00010000
=
00110000 = 0.5 + 0.25 = 0.75
rules:
1-0 = 1
1-1=0
0-1 = 1 with a borrow (all zeros upstream become 1 until first 1 hit which becomes 0), if there are no ones upstream, the overflow flag is set (overflow/borrow).

Ah, thanks! Its the 0-1 that is confusing me... but if I had to do 0.25-1 then wouldnt that be: 11010000? but that is not -0.75, it gives me -1.25? is that because there is overflow?
 
with the sign bit as bit 7, you don't use a '1' for the bit, you use a zero, so a -1 would look like 10111111,
so .25 plus - 1 would look like:

00010000
10111111
and adding them, you'd get:
11001111
which is -.75

for instance, if you don't imply the decimal, a 1 looks like 00000001, a zero 00000000, and minus one 11111111 (the next one below zero), and minus two 11111110, minus three 11111101, etc... it's called sign bit extension for negative numbers
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top