Short to Byte HW #1
Why?
byte by = 127; short sh = -30999; by = (byte)sh; System.out.println(by);
The lines of code ahead will out put a number of -23. This is because we are trying to fit a short which is bigger than a byte which maximum is 127 or -128. In a ideal scenario -30999 would reduce to -999 but it cannot because a byte is too small. Because these numbers are set in 8 bits, then it means that -999 is the same as -23 in this bit system.
When does it make sense to cast:
-It makes sense when you need to round up or down a number.
-When something is held in a big data type but it can fit in a smaller data type. it would make sense to save space.
Summary of Class:
In class we began to learn the basics of casting data types. We also learned when to use them and why we should use them. As well, we learned when will casting be not helpful and when can it be faulty. We were able to change int to double and double to int. Apart from casting we also practiced if/else statements and some booleans. Also, we learned a new idea in class of Full Conditional Items as else if, but we did not manage to learn a lot about this topic, we only hovered over it.












