Search site Dead Hackers Society
Other BBSes »
 
 
Demoscene   º   Coding   º   CT60   º   Buy/sell   º   Misc/crap   º   Alive magazine   º   SNDH/Tracking

Misc/crap BBS
 
Re: verpak
Posted by: chemmad Oct,29.2015-03:08 

#include <stdio.h>
#include <string.h>
#include <math.h>
typedef union int_of_float {
unsigned int i;
float f;
}getal;

typedef union a_b_c_d {
char a0;
char a1;
char a2;
char a3;
} rij;

/* Druk een int af in bit-representatie */
void druk_bits(int v)
{
int i, masker=1 << 31; /* masker = 100 ... 0 */
for (i=1;i<=32;++i){
putchar(((v & masker)==0)? '0':'1');
v <<= 1;
if (i % 8 ==0 && i !=32)
putchar(' ');
}}

/* Verpak 4 kararakters in een int */
void verpak(char *str_ptr )
{
FILE *fip;
int i;
int p=0;
char *s2;
s2=(char *) calloc(5 , sizeof(char));
strcat(s2,str_ptr);
int j=0;
char temp;
for (i=3;i>=0;--i)
{

printf("%d",i);
temp=str_ptr[i];
if (temp!=0) s2[j]=temp;
else s2[j]=' ';
j++;
}
printf("string %s string %s",str_ptr,s2);
if((fip = fopen("TSET", "w"))==NULL) {
printf("Cannot open file. ");
exit(1);
}
if (fip != NULL)
{
fputs(s2, fip);
fclose(fip);
}
}
void pak_uit(int p, char *a,char *b, char *c, char *d)
{
*a=(p & 0xff000000)>>24;
*b=(p & 0xff0000)>>16;
*c=(p & 0xff00)>>8;
*d=((p & 0xff));
}

int main(int argc, char **argv)
{
FILE *fid;
FILE *fp;
getal n;
getal pi;
float g;
int i;
char a,b,c,d;
char u,v,w,x;
char *s;
int p=0;
/* Mijn functie */

//pi.f=3.14159;
pi.f=100.0;
pak_uit(pi.i,&u,&v,&w,&x);

druk_bits(pi.i);
putchar(' ');
s=(char *) calloc(5 , sizeof(char));
s[0]=u;
s[1]=v;
s[2]=w;
s[3]=x;
s[4]=0;
printf("%s ",s);
printf("pi = %d ",pi.i);
verpak(s);


putchar(' ');
if((fp = fopen("TEST", "w"))==NULL) {
printf("Cannot open file. ");
exit(1);
}
if (fp != NULL)
{
fputs(s, fp);
fclose(fp);
}
// title="readbinary"
float *ar;

fid = fopen("TSET","r");
ar = (float*) calloc(1, sizeof(float));
fread(ar, sizeof(float), 1, fid);
for(i=0; i<1; i++)
printf("%f ", ar[i]);
fclose(fid);
n.f=ar[0];
n.f=trunc(n.f);
printf("%0.00f ",n.f);
printf("%d ",n.i);
druk_bits(n.i);
return 0;
}





[All messages in this thread]

Topic Posted by  Date 
verpak chemmad Oct,27.2015-14:26
  Re: verpak chemmad Oct,29.2015-03:08
    Re: verpak dammehc Dec,01.2015-19:35


Reply to this message
Name:
Topic:
Human verification (enter the text of the ASCII-art below):

   _   _   _   _  _  _        _  
 _|_ _|_ _|_ _|_ (_)  ) |_|_ / \ 
  |   |   |   |  (_) /_   |  \_/
Message:




© 1994-2017 Dead Hackers Society Contact: Anders Eriksson