sábado, 26 de agosto de 2023

 Código en C para convertir Sistema Decimal a Binario y Viceversa

 El Código es un C sencillo y se puede mejorar sustancialmente

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

// Initializing methods
int presentacion();
int menu();
int calcBinaryToDec();
double getPow(double value1, double position);
int isPair(int param);

int main() {
    presentacion();
    int menuOpcion;
    menuOpcion = 1;
    
    while(menuOpcion==1 || menuOpcion==2){
       
        menu();
        printf("Ingrese numero de opcion: ");
        scanf("%d", &menuOpcion);
        printf("\n");
               
        if(menuOpcion==1){
            calcBinaryToDec();
        }
        else if(menuOpcion==2){
            calDecToBinary();
        }
        else
            printf("******** Fin ********\n");
    }
    return 0;
}

int presentacion(){
    printf("*********************\n");
    printf("** ADRIAN BORDONES **\n");
    printf("*********************\n");
    return 0;
}

int menu(){
    printf("Opciones de Calculo\n");
    printf("1 - Binario a Decimal\n");
    printf("2 - Decimal a Binario\n");
    printf("0 - Salir\n");
    return 0;
}

int calDecToBinary() {
    int decNum;
    int nextValue;
    int j;
    int largoCadena;
    
    char cadena[10] = "";
    char localValue[2];
    char cadenaFinal[10] = "";
    char tempValue, newTemp;
    
    double resultDiv;
    int isPairValue;
    
    printf("Calculo Decimal a Binario\n");
    printf("Ingrese Numero Decimal: ");   
    scanf("%d", &decNum);       
    nextValue = decNum;
    while(nextValue != 0)
    {
        if(decNum > 1)
        {
            isPairValue = isPair(decNum);
            resultDiv = decNum/2;       
            if(isPairValue==1)
                tempValue = '0';
            else
            {
                tempValue = '1';
                resultDiv = trunc(resultDiv);
            }
            strncat(cadena, &tempValue, 1);
            decNum = (int)resultDiv;
            nextValue = 1;                   
        }
        else
        {
            tempValue = '1';
            isPairValue = isPair(decNum);
            resultDiv = 1;
            strncat(cadena, &tempValue, 1);
            nextValue = 0;
        }
    }   
    largoCadena = strlen(cadena);   
    for(j = largoCadena-1; j >= 0; j--) {
        newTemp = cadena[j];       
        localValue[0] = newTemp;
        localValue[1] = '\0';       
        strcat(cadenaFinal, localValue);
    }   
    printf("Valor Binario: %s\n", cadenaFinal);       
    printf("---------------------\n");
    
    return 0;   
}

int isPair(int param) {
    int result = 0;
    if ((param % 2) == 0)
        result = 1;
    else
        result = 0;
    return result;                       
}

int calcBinaryToDec() {
    // variables
    int binaryNum, i;
    //char numString[25];
    char newString[25];
    int largo, iParam, iRespuesta, iSummary;
    double param1, respuesta, lposition;
    int result;
    char valor0;
    char valor1[2];
    double summary;   
    summary=0;
     
    printf("Calculo de Binario a Decimal\n");
    printf("Ingrese Numero Binario: ");
    scanf("%d", &binaryNum);   
    
    // sprintf : convert integer variable to string
    sprintf(newString, "%d", binaryNum);
    
    // reverse string binary value to process inside for loop
    largo = strlen(newString);   
    for(i=largo-1;i>=0;i--) {
        valor0 = newString[i];       
        valor1[0] = valor0;
        valor1[1] = '\0';
        
        // atoi : conver this piece of string into integer value
        result = atoi(valor1);
        
        // cast values from int to double
        param1 = (double)result;       
        lposition = (double)(largo - (i+1));
       
        // call function to get power of number value with position     
        respuesta = getPow(param1, lposition);
        
        // add to summary calc
        summary = summary + respuesta;       
        iParam = (int)param1;
        iRespuesta = (int)respuesta;
    }
    
    iSummary = (int)summary;
    printf("Valor Decimal: %d\n", iSummary);
    printf("---------------------\n");  
    return 0;
}

double getPow(double value1, double position)
{
    double result = 0;
    double binRef = 2; // base calculo binario
    double refResult = pow(2, position);       
    if (value1 == 1) // si binario es 1 devuelve resultado, de lo contrario 0
        result = refResult;
    else
        result = 0;
    return result;
}

 

Elaborado el Sábado 27 de Agosto de 2023


martes, 6 de septiembre de 2022

Exportación a PDF

 Exportación

 using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;

namespace testDxReports1
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            System.IO.MemoryStream stream1 = new System.IO.MemoryStream();
            DevExpress.XtraReports.UI.XtraReport reporte = new XtraReport1(String.Format("{0}", Request["personType"]));
            reporte.ExportToPdf(stream1);
            Response.Clear();
            Response.ContentType = "application/octet-stream";
            Response.AppendHeader("Content-Disposition", String.Format("attachment; filename=report.{0}", "pdf"));
            Response.AddHeader("content-length", stream1.Length.ToString());
            Response.BinaryWrite(stream1.ToArray());
            Response.End();
            stream1.Close();
        }
    }
}

 

jueves, 13 de febrero de 2020

Oracle Pl Sql : Devolver un objeto tabla desde una función

Oracle: return a »table« from a function
 
With collections and the table() function, a function can return a table that can be queried in an SQL statement. This is demonstrated in the following example.
Record type
First, we need to create a record type. In this example, the records consist of two attributes: i, a number and n, a varchar2.
The record type is created with create type:

create or replace type t_record as object (
  i number,
  n varchar2(30)
);
/


Table type
Based on the record type, we can now create a table type.

create or replace type t_table as table of t_record;
/


Function
With the table type, we're ready to create a function.
Note: the function returns a t_table.

create or replace function return_table return t_table as
  v_ret   t_table;
begin

 --
 -- Call constructor to create the returned
 -- variable:
 --

    v_ret  := t_table();

 --
 -- Add one record after another to the returned table.
 -- Note: the »table« must be extended before adding
 -- another record:
 --

    v_ret.extend; v_ret(v_ret.count) := t_record(1, 'one'  );
    v_ret.extend; v_ret(v_ret.count) := t_record(2, 'two'  );
    v_ret.extend; v_ret(v_ret.count) := t_record(3, 'three');

 --
 -- Return the record:
 --

    return v_ret;

end return_table;
/

Using the function
In order to use the function's returned value as a table in a SQL statement, we have to enclose the function within the table() statement. From the SQL's perspective, the table(…) construct behaves as though it were an actual table.

select * from table(return_table);


Using bulk collect
The previous function is rather boring in that it returns the same result set each time it is called.
The following function makes that a bit more dynamic. It takes a parameter that specifies the maximum count of records to be returned.
Then, it uses rownum and bulk collect to select a result set into a variable of type t_table and returns it.

create or replace function return_objects (
    p_max_num_rows in number
)
return t_table as
    v_ret   t_table;
begin

    select
      t_record(rownum, object_name)
    bulk collect into
      v_ret
    from
      user_objects
    where
      rownum <= p_max_num_rows;
 
    return v_ret;
 
end return_objects;
/


Using the function
Again, this function is used with the table(…) construct:

select * from table(return_objects(5));

Cleaning up
Dropping the functions and record types to clean up:

drop type     t_table;
drop type     t_record;
drop function return_table;
drop function return_objects;


Thanks
Thanks to Vikram Singh Rathore for a suggestion for this page.


Original Page Source: renenyffenegger.ch/notes/development/databases/Oracle/PL-SQL/collection-types/return-table-from-function/index

miércoles, 10 de abril de 2019

Lars-Luis Linek A Vida lyrics

Lars-Luis Linek a vida 

A vida

Amei a saudade portuguesa,
Cheia de amor e de tristeza,
Rosa espinhosa esta flor
Cheia de amor e de dor

Assim é a vida a vida é assim,
O meu destino saudade sem fim
Assim é a vida a vida é assim,
O meu destino saudade sem fim

A minha vida cheia de surpresas,
inseguridades e incertezas,
Eu quero saber o que fazer,
Entre o sofrimento e o prazer

Assim é a vida a vida é assim,
O meu destino saudade sem fim,
Assim é a vida a vida é assim,
O meu destino saudade sem fim