Skip to content

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 

Repository files navigation

Byte-Explorer-in-C-low-level

#include <stdio.h>

void dec(unsigned char number) {
    printf("Decimal: %6d\n", number);
}

void hex(unsigned char number) {
    printf("Hexadecimal: %X\n", number);
}

void bin(unsigned char number) {
    printf("Binário:     ");

    for (int i = 7; i >= 0; i--) {
        if ((number & (1 << i)) != 0){
            printf("1");
        } else {
            printf("0");
        }
    }
    
    puts("");
}

int main() {
    unsigned char number;
    
    puts(
        "---------------\n"
        " BYTE EXPLORER\n"
        "---------------\n"
    );
    
    printf("Digite um número entre 0 e 255: ");
    
    if (scanf("%hhu", &number) != 1) {
        printf("Número inválido!");
        return 1;
    }
    
    puts("");
    
    dec(number);
    hex(number);
    bin(number);
    
    return 0;
}

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors