Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

When trying to print binary sentiences in my C code, for some reason line 3, 5, 10, 13 do not print the portion of the

When trying to print binary sentiences in my C code, for some reason line 3, 5, 10, 13 do not print the portion of the sentence correctly: image text in transcribed

Here is the code for the binary portion (in C):

void binDump (void *addr, int len) {

int i;

unsigned char buff[17];

unsigned char *pc = (unsigned char*)addr;

for (i = 0; i

if ((i % 6) == 0) {

if (i != 0)

printf(" %s ", buff);

printf(" %07x: ", i); //prints address

}

int j;

for(j = 0; j

printf("%d", !!((pc[i]

}

printf(" ");

if ((pc[i] 0x7e)) /on-printable chars

buff[i % 6] = '.';

else

buff[i % 6] = pc[i];

buff[(i % 16) + 1] = '\0'; //clear array

}

while ((i % 6) != 0) { //'.' fill last line

printf ("........ ");

i++;

}

printf (" %s ", buff); //prints human value

}

int main (int argc, char *argv[]) {

FILE *fp;

fp = fopen(argv[2], "r");

fseek(fp, 0L, SEEK_END);

int size = ftell(fp);

fseek(fp, 0L, SEEK_SET);

char buff[size];

fread(buff, size, 1, fp);

binDump(&buff, size);

fclose(fp);

return 0;

}

This is a very strange error since the binary sequences are correct, but they do not print the correct characters.

0000000 01 110101 01101000 01101101 00100000 01101000 01100101 uhm he 0000006: 01101100 01101 100 01101111 00100000 01101010 01101111 llo jo 000000c 01 110010 011001 00 01100001 01101110 00100000 0110 1000 0000012 01101111 01110111 00100000 01110111 01100001 01110011 OW was 0000018 00100000 01111001 01101111 0111010 1 01110010 00 100000 your 000001e 01100100 01100001 01111001 00100000 01110100 01101111 d 0000024 01100100 01100001 01111001 00001010 01100100 01101111 day do 000002a: 00100000 01111001 01 101111 01110101 00100000 01101100 you l 0000030 01 100 1001 01101011 01100101 00100000 01110111 01101111 ike wo 0000036 011 10010 01101011 01101001 01101110 01100111 00100000 rking 000003c 01 100001 011101 00 00100000 0110010 1 01101100 00 100000 0000042 01 110000 01101111 01101100 01101100 01101111 00100000 pollo 0000048 01 100 1100 0110 1111 01100011 01101111 00111111 00001010 loco? 000004e 01 100100 01101111 00100000 01011001 01001111 01010101 d 0000054 00100000 0110 1101 01101001 01110011 01110011 00100000 miss 000005a 01110011 01110101 01100010 01110111 01100001 01111001 subway 0000060 001 11111 00100001 00001010

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Structured Search For Big Data From Keywords To Key-objects

Authors: Mikhail Gilula

1st Edition

012804652X, 9780128046524

More Books

Students also viewed these Databases questions