#include
#include
int main()
{
int array[16];
char input;
int index = 0;
int i = 15, j = 0;
int hasil = 0, error = 0;
printf("\nAhmad Ridha \n");
printf("\n==============================\n\n");
printf("\nKeterangan: Bit Pertama Harus 0\n");
printf("\nMasukkan integer biner dengan panjang 16 bit:\n");
while((input = getchar()) != '\n')
{
if(input >= '0' && input <= '1')
{
if(index < 16) {
array[index] = input-48;
index++;
}
else {
array[index] = '\0';
break;
}
}
else {
error = 1;
break;
}
}
if(error == 1) {
printf("Error input ...\n");
error = 0;
}
i = index-1;
for(; index > 0 ; index--)
{
if(array[i] == 1)
{
array[i] = pow(2,j);
}
else
{
array[i] = 0;
}
if(i == 0)
array[i] = -array[i];
hasil += array[i];
i--;
j++;
}
if(error == 0)
{
printf("Integer desimalnya: \n%d\n", hasil);
input = i = j = index = hasil = 0;
error = 0;
}
return 0;
}
#include
int main()
{
int array[16];
char input;
int index = 0;
int i = 15, j = 0;
int hasil = 0, error = 0;
printf("\nAhmad Ridha \n");
printf("\n==============================\n\n");
printf("\nKeterangan: Bit Pertama Harus 0\n");
printf("\nMasukkan integer biner dengan panjang 16 bit:\n");
while((input = getchar()) != '\n')
{
if(input >= '0' && input <= '1')
{
if(index < 16) {
array[index] = input-48;
index++;
}
else {
array[index] = '\0';
break;
}
}
else {
error = 1;
break;
}
}
if(error == 1) {
printf("Error input ...\n");
error = 0;
}
i = index-1;
for(; index > 0 ; index--)
{
if(array[i] == 1)
{
array[i] = pow(2,j);
}
else
{
array[i] = 0;
}
if(i == 0)
array[i] = -array[i];
hasil += array[i];
i--;
j++;
}
if(error == 0)
{
printf("Integer desimalnya: \n%d\n", hasil);
input = i = j = index = hasil = 0;
error = 0;
}
return 0;
}
Tidak ada komentar:
Posting Komentar