Primitive Data Types

27 0 0
                                        

I thought i could just leave this out but i can't since we need this on the discussion of the precedence of math operation.

private static int speed;

speed = 60;

Normally, the format of variable declaration is like this, "int speed". It means that a variable named speed has a type of integer. Integer is just one of the primitive types. Below are the following primitive data types:

1. byte - based in oracle tutorial, byte is an 8 bit signed, two's complement integer. It has a range of -128 to + 127. And it was said that this is useful in saving memory in large arrays which i haven't tried since i don't know anything yet.

In mathematics, 1 byte = 8 bit. What are these? 

       We are familiar with the decimal numbering system. I mean we count from 0, 1, 2, and so on... These counting of ours has a based of 10. Example 421 which in words is four hundred twenty one.

4 x 100 = 400

2 x 10 = 20

1 x 1 = 1

You see the 1, 10, and 100.. in this decimal numbering system. We increased the value by the power of 10. So, using exponential form, we can see that below we used the power of 10.

1 x 10 exp 0 = 1

1 x 10 exp 1 = 10

1 x 10 exp 2 = 100

So, to go back to main question, what is a byte? A byte is equal to 8 bit. This byte and bit are terms used in the binary numbering system. Binary has a based of 2. That means that instead of using a power of 10, in binary, we a power of 2. Example, the number 22 with a based of 10;

22 is equal to:

2 x 10 = 20

2 x 1 = 2                                            

  in binary: 22 is equal to 0001 0110

starting with farthest 1 in the left:

1 x 2 exp 4 = 16

0 x 2 exp 3 = 0

1 x 2 exp 2 = 4

1 x 2 exp 1 = 2

0 x 2 exp 0 = 0

if you add the 2 + 4 + 16 = 22... so 1 byte = 1111 1111 bits. These binary is useful in electronics. To go back, 8 bit signed, the signed means it can have a positive or negative value as well. Those bits can have a positive and negative value as well. Let us say:

-22

Usually the farthest to the left is the signed bit. In mathematics, it would be easy to add another bit to the far most left just for the sake of signed bits.

22 =  0 0001 0110

-22 = 1 0001 0110

That additional one is the signed bit. If there is a 1 in the left most, it means, it is negative if 0, then, it is positive. But the problem with this is that in digital electronics, you cannot add a spare bit in the left most part of the value. So, what they did is that, 

- 22 ===> 1 0001 0110 becomes like this 1001 0110

Instead of adding an additional bit, they make use of the far left most bit as a signed bit. But the problem is this, they could not maximize the value or the magnitude because the far left most bit is just a signed bit. That is why they developed the computation called one's complement. In one's complement, you add an subtract like this and just ignore the signed bit. 

Java codes i learned onlineWhere stories live. Discover now