Skip to content

abranhe/binary.c

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation




binary.c: An small C library to work with binary numbers



In mathematics and digital electronics, a binary number is a number expressed in the base-2 numeral system or binary numeral system, which uses only two symbols: typically 0 and 1.

Installation

Installing using Clib

$ clib install abranhe/binary.c

Usage

#include <stdio.h>
#include "binary.h"

int main() {
	printf("%d\n", is_binary(1010));
	// 1
	printf("%ld\n", to_decimal(10000000011));
	// 1027
	printf("%lld\n", to_binary(1000));
	// 1111101000
}

API

bool is_binary(long binary);

Returns true (1) if the number is binary, otherwise return false (0)

Params:
  • binary: long binary number

long to_decimal(long long binary);

Returns a long decimal number from a binary number

Params:
  • binary: long binary number

long long to_binary(long decimal);

Returns a binary number from a decimal number

Params:
  • decimal: a long decimal number

Team

Carlos Abraham Logo
Carlos Abraham

License

MIT License © Carlos Abraham