Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

abranhe/binary.c

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

AltStyle によって変換されたページ (->オリジナル) /