# Can someone please explain to me how overflow works in binary coding?

Watch
Announcements

Page 1 of 1

Go to first unread

Skip to page:

I understand how to do negative numbers (convert then plus one) to the code, but i'm still not sure about over/under flow (in binary code). Also hexidecimal, base 15 right? But I still haven't fully got my head around that also! Help!!?!

0

reply

Report

#3

(Original post by

I understand how to do negative numbers (convert then plus one) to the code, but i'm still not sure about over/under flow (in binary code). Also hexidecimal, base 15 right? But I still haven't fully got my head around that also! Help!!?!

**john2054**)I understand how to do negative numbers (convert then plus one) to the code, but i'm still not sure about over/under flow (in binary code). Also hexidecimal, base 15 right? But I still haven't fully got my head around that also! Help!!?!

Very simple.... let's say you have this binary addition:

The last bit on the left cannot be stored as the value is too big. Instead of the expected 8 bits total, this addition has produced 9 bits. So in this case, the CPU drops the overflow digit, as it cannot be stored.

0

reply

(Original post by

In binary?

Very simple.... let's say you have this binary addition:

The last bit on the left cannot be stored as the value is too big. Instead of the expected 8 bits total, this addition has produced 9 bits. So in this case, the CPU drops the overflow digit, as it cannot be stored.

**Aklaol**)In binary?

Very simple.... let's say you have this binary addition:

The last bit on the left cannot be stored as the value is too big. Instead of the expected 8 bits total, this addition has produced 9 bits. So in this case, the CPU drops the overflow digit, as it cannot be stored.

11111111+00000010=?

0

reply

Report

#5

pragmatically, yes, it pretty much resets, but that's not technically whats going on. What happens is that numbers such as 100000000 in binary cant be stored in 1 byte, so the 1 gets dropped off, and you're left with 00000000. If you add 2, it's similar 11111111 + 00000010 = 10000001, but thats too big, so the left 1 gets dropped off and youre left with 00000001.

Posted from TSR Mobile

Posted from TSR Mobile

0

reply

Report

#6

(Original post by

Okay so if an 8 bit system were to max out exactly, it just resets? Is that right? And then say if it were two added, instead of one, what then?

11111111+00000010=?

**john2054**)Okay so if an 8 bit system were to max out exactly, it just resets? Is that right? And then say if it were two added, instead of one, what then?

11111111+00000010=?

0

reply

Report

#7

Also Hex is just base sixteen, it uses 16 digits from 0-F. So 10 would be "A" in hex , 15 would be "F" in hex and 16 would be "10". Hex is useful for doing stuff like bit masks and bit flags and is pretty much just concise binary. One hex digit can store the same as 4 binary digits. For example if you want a byte that is 255, rather than writing " 11111111" in binary, you just write "FF" in hexadecimal. A practical example of this is RGBA colour codes. These are 4 byte numbers that represent all of the colours. In binary, that would be 32 binary digits, but in hex, it's only 8 and thats why many colour codes are written in Hex.

Why use Hex and not just Decimal?

I believe that computers convert from Hex to binary much quicker than it can with decimal since 16 is exactly 2^4

Posted from TSR Mobile

Why use Hex and not just Decimal?

I believe that computers convert from Hex to binary much quicker than it can with decimal since 16 is exactly 2^4

Posted from TSR Mobile

0

reply

(Original post by

pragmatically, yes, it pretty much resets, but that's not technically whats going on. What happens is that numbers such as 100000000 in binary cant be stored in 1 byte, so the 1 gets dropped off, and you're left with 00000000. If you add 2, it's similar 11111111 + 00000010 = 10000001, but thats too big, so the left 1 gets dropped off and youre left with 00000001.

Posted from TSR Mobile

**BobBobson**)pragmatically, yes, it pretty much resets, but that's not technically whats going on. What happens is that numbers such as 100000000 in binary cant be stored in 1 byte, so the 1 gets dropped off, and you're left with 00000000. If you add 2, it's similar 11111111 + 00000010 = 10000001, but thats too big, so the left 1 gets dropped off and youre left with 00000001.

Posted from TSR Mobile

0

reply

(Original post by

Also Hex is just base sixteen, it uses 16 digits from 0-F. So 10 would be "A" in hex , 15 would be "F" in hex and 16 would be "10". Hex is useful for doing stuff like bit masks and bit flags and is pretty much just concise binary. One hex digit can store the same as 4 binary digits. For example if you want a byte that is 255, rather than writing " 11111111" in binary, you just write "FF" in hexadecimal. A practical example of this is RGBA colour codes. These are 4 byte numbers that represent all of the colours. In binary, that would be 32 binary digits, but in hex, it's only 8 and thats why many colour codes are written in Hex.

Why use Hex and not just Decimal?

I believe that computers convert from Hex to binary much quicker than it can with decimal since 16 is exactly 2^4

Posted from TSR Mobile

**BobBobson**)Also Hex is just base sixteen, it uses 16 digits from 0-F. So 10 would be "A" in hex , 15 would be "F" in hex and 16 would be "10". Hex is useful for doing stuff like bit masks and bit flags and is pretty much just concise binary. One hex digit can store the same as 4 binary digits. For example if you want a byte that is 255, rather than writing " 11111111" in binary, you just write "FF" in hexadecimal. A practical example of this is RGBA colour codes. These are 4 byte numbers that represent all of the colours. In binary, that would be 32 binary digits, but in hex, it's only 8 and thats why many colour codes are written in Hex.

Why use Hex and not just Decimal?

I believe that computers convert from Hex to binary much quicker than it can with decimal since 16 is exactly 2^4

Posted from TSR Mobile

0

reply

Report

#10

**john2054**)

Okay so if an 8 bit system were to max out exactly, it just resets? Is that right? And then say if it were two added, instead of one, what then?

11111111+00000010=?

http://teaching.idallen.com/dat2343/...0_overflow.txt

0

reply

**BobBobson**)

Also Hex is just base sixteen, it uses 16 digits from 0-F. So 10 would be "A" in hex , 15 would be "F" in hex and 16 would be "10". Hex is useful for doing stuff like bit masks and bit flags and is pretty much just concise binary. One hex digit can store the same as 4 binary digits. For example if you want a byte that is 255, rather than writing " 11111111" in binary, you just write "FF" in hexadecimal. A practical example of this is RGBA colour codes. These are 4 byte numbers that represent all of the colours. In binary, that would be 32 binary digits, but in hex, it's only 8 and thats why many colour codes are written in Hex.

Why use Hex and not just Decimal?

I believe that computers convert from Hex to binary much quicker than it can with decimal since 16 is exactly 2^4

Posted from TSR Mobile

0

reply

(Original post by

The CPU (usually) has carry and overflow flags in it's status register - you can look at these after doing your arithmetic to see what happened... i.e. you don't just get a 'wrong answer' you get some diagnostics you can choose to look at or not.

http://teaching.idallen.com/dat2343/...0_overflow.txt

**Joinedup**)The CPU (usually) has carry and overflow flags in it's status register - you can look at these after doing your arithmetic to see what happened... i.e. you don't just get a 'wrong answer' you get some diagnostics you can choose to look at or not.

http://teaching.idallen.com/dat2343/...0_overflow.txt

0

reply

Report

#13

Lemme just count up for you in hex:

1,2,3,4,5,6,7,8,9,A,B,C,D,E,F,10 ,11,12,13,14,15,16,17,18,19,1A,1 B,1C,1D,1E,1F

Thats 1-31 in hexadecimal

Posted from TSR Mobile

1,2,3,4,5,6,7,8,9,A,B,C,D,E,F,10 ,11,12,13,14,15,16,17,18,19,1A,1 B,1C,1D,1E,1F

Thats 1-31 in hexadecimal

Posted from TSR Mobile

0

reply

(Original post by

Lemme just count up for you in hex:

1,2,3,4,5,6,7,8,9,A,B,C,D,E,F,10 ,11,12,13,14,15,16,17,18,19,1A,1 B,1C,1D,1E,1F

Thats 1-31 in hexadecimal

Posted from TSR Mobile

**BobBobson**)Lemme just count up for you in hex:

1,2,3,4,5,6,7,8,9,A,B,C,D,E,F,10 ,11,12,13,14,15,16,17,18,19,1A,1 B,1C,1D,1E,1F

Thats 1-31 in hexadecimal

Posted from TSR Mobile

0

reply

Report

#15

(Original post by

20,21,22,23,24,25,26,27,28,29,2a ,2b,2c,2d,2e,2f,30,31,32,33,34,3 5,36,37,38,39,3a,3b,3c,3d,3e,3f and is that 32-63? how do you remember all of this?

**john2054**)20,21,22,23,24,25,26,27,28,29,2a ,2b,2c,2d,2e,2f,30,31,32,33,34,3 5,36,37,38,39,3a,3b,3c,3d,3e,3f and is that 32-63? how do you remember all of this?

Posted from TSR Mobile

2

reply

(Original post by

yep thats right. Hexadecimal is rarely used for counting and maths, its mainly used for storing binary concisely, so you dont need to memorise every numbers equivalent in hex. You just need to know how to work it out.

Posted from TSR Mobile

**BobBobson**)yep thats right. Hexadecimal is rarely used for counting and maths, its mainly used for storing binary concisely, so you dont need to memorise every numbers equivalent in hex. You just need to know how to work it out.

Posted from TSR Mobile

0

reply

Report

#17

(Original post by

Is there a program you can use to convert hex to decimal?

**john2054**)Is there a program you can use to convert hex to decimal?

If you want to do it yourself then just go up in powers of 16 from the right, starting with to the power of zero.

For example if you had 6A4 then you would do this

4*16^0 = 4

A=10 so 10*16^1 = 160

6*16^2 = 1536

Add them all together you get 1700

1

reply

(Original post by

There are many online. http://www.binaryhexconverter.com/he...imal-converter

If you want to do it yourself then just go up in powers of 16 from the right, starting with to the power of zero.

For example if you had 6A4 then you would do this

4*16^0 = 4

A=10 so 10*16^1 = 160

6*16^2 = 1536

Add them all together you get 1700

**jordanshelley97**)There are many online. http://www.binaryhexconverter.com/he...imal-converter

If you want to do it yourself then just go up in powers of 16 from the right, starting with to the power of zero.

For example if you had 6A4 then you would do this

4*16^0 = 4

A=10 so 10*16^1 = 160

6*16^2 = 1536

Add them all together you get 1700

8*16^0=8

11*16^1=176

3*16^2=768

15*16^3=61440

10*16^4=655360

1*16^5=1048576

corrected sum=1766328

this checks out

Also can a hexidecimal bit be 0?

0

reply

Report

#19

(Original post by

here i will set myself a task 1af3b8=

8*16^0=8

11*16^1=176

3*16^2=768

16*16^3=65536

10*16^4=655360

1*16^5=1048576

sum=1770424 is this right?

Also can a hexidecimal bit be 0?

**john2054**)here i will set myself a task 1af3b8=

8*16^0=8

11*16^1=176

3*16^2=768

16*16^3=65536

10*16^4=655360

1*16^5=1048576

sum=1770424 is this right?

Also can a hexidecimal bit be 0?

**15*16^3=61440**

That's quite a common mistake though. We know hex is base-16 and we know F is the last letter so we think automatically that F must be 16, I've done it myself

But apart from that the rest is correct. And yes any of the bits can be 0

0

reply

X

Page 1 of 1

Go to first unread

Skip to page:

### Quick Reply

Back

to top

to top