You are Here: Home

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

1. 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!!?!
2. (Original post by john2054)
x

Posted from TSR Mobile
3. (Original post by 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!!?!
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.
4. (Original post by 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.
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=?
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
6. (Original post by 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=?
It doesn't matter how many extra bits are added. If it's an overflow error, the CPU will simply drop all the extra bits. If the CPU physically can't store a piece of data, then it can't do anything else other than to drop the extra bits. If a 8 bit system was to max out on memory, virtual memory would be created. If all else fails and there isn't any main memory, virtual memory or hard disk space left, then the CPU wouldn't store anymore data.
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
8. (Original post by 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
That answered my question thanks Bob.
9. (Original post by 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
I thought you said that 16 was 10 in hex i mean, or was that 01? oh dear i am getting confused.
10. (Original post by 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=?
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
11. (Original post by 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
16=00 in hex right?
12. (Original post by 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
Sorry joined up, but i've only been doing this java course for two days, and that overfow flag stuff you just shared, goes like waay over my head!
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

Posted from TSR Mobile
14. (Original post by 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

Posted from TSR Mobile
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?
15. (Original post by 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?
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
16. (Original post by 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
Is there a program you can use to convert hex to decimal?
17. (Original post by john2054)
Is there a program you can use to convert hex to decimal?
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
18. (Original post by 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
here i will set myself a task 1af3b8=
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?
19. (Original post by 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?
One mistake is that F is actually 15 so it would actually be 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

TSR Support Team

We have a brilliant team of more than 60 Support Team members looking after discussions on The Student Room, helping to make it a fun, safe and useful place to hang out.

This forum is supported by:
Updated: September 15, 2016
Today on TSR

### Last-minute PS help

100s of personal statements examples here

### Loneliness at uni

Discussions on TSR

• Latest
• ## See more of what you like on The Student Room

You can personalise what you see on TSR. Tell us a little about yourself to get started.

• Poll
Useful resources

## Groups associated with this forum:

View associated groups
Discussions on TSR

• Latest
• ## See more of what you like on The Student Room

You can personalise what you see on TSR. Tell us a little about yourself to get started.

• The Student Room, Get Revising and Marked by Teachers are trading names of The Student Room Group Ltd.

Register Number: 04666380 (England and Wales), VAT No. 806 8067 22 Registered Office: International House, Queens Road, Brighton, BN1 3XE

Reputation gems: You get these gems as you gain rep from other members for making good contributions and giving helpful advice.