I made a method to assembler 8 bit into a unique byte.
this follow.
This servers to assembles the 7 flags of cpu.
public static int juntar()
{
int tmp = 0x0 ; //inicializo com 00000000 senão inicializar não aceita de cara o |=
tmp = (
((flagN) ? 128 :0) |
((flagV) ? 64 : 0) |
32 |
((flagB) ? 16 : 0) |
((flagD) ? 8 : 0) |
((flagI) ? 4 : 0) |
((flagZ) ? 2 : 0) |
((flagC) ? 1 : 0)
) ;
return tmp; //I dont know what but if i put byte like a return type this return -78
}
//supossing that i put this value on the variables
byte tmp;
flagN = true ; //10000000
flagV = false; //00000000
//00100000
flagB = true ; //00010000
flagD = false; //00000000
flagI = false; //00000000
flagZ = true ; //00000010
flagC = false; //00000000
//10110010 = 178 decimal or B2 hexa.
Then, this method , if i put the byte type to return it return -78 but if i put int it return 178 , 178 is that correct.
Why this occors?
I need this number, the correct, in byte. And i cannot covert the int to byte?
I try Byte.valueOf(tmp) , but it not works too.
If you can help me I will thanks you !!
this follow.
This servers to assembles the 7 flags of cpu.
public static int juntar()
{
int tmp = 0x0 ; //inicializo com 00000000 senão inicializar não aceita de cara o |=
tmp = (
((flagN) ? 128 :0) |
((flagV) ? 64 : 0) |
32 |
((flagB) ? 16 : 0) |
((flagD) ? 8 : 0) |
((flagI) ? 4 : 0) |
((flagZ) ? 2 : 0) |
((flagC) ? 1 : 0)
) ;
return tmp; //I dont know what but if i put byte like a return type this return -78
}
//supossing that i put this value on the variables
byte tmp;
flagN = true ; //10000000
flagV = false; //00000000
//00100000
flagB = true ; //00010000
flagD = false; //00000000
flagI = false; //00000000
flagZ = true ; //00000010
flagC = false; //00000000
//10110010 = 178 decimal or B2 hexa.
Then, this method , if i put the byte type to return it return -78 but if i put int it return 178 , 178 is that correct.
Why this occors?
I need this number, the correct, in byte. And i cannot covert the int to byte?
I try Byte.valueOf(tmp) , but it not works too.
If you can help me I will thanks you !!