Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Binary Representation

Posted on 2005-04-18
4
Medium Priority
?
495 Views
Last Modified: 2013-11-15
Hello,

Can someone show me how to get the binary representation of any charachter?
Preferably store it in a int array.

Thanks
0
Comment
Question by:Hurb
  • 2
4 Comments
 
LVL 30

Expert Comment

by:Axter
ID: 13808412
Hi Hurb,
You can use itoa if your compiler supports this extended function.
Example:

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

   char buffer[20];
   int  i = 3445;
   _itoa( i, buffer, 2  );
   printf( "String of integer %d (radix 2): %s\n", i, buffer );


David Maisonave :-)
Cheers!
0
 
LVL 30

Accepted Solution

by:
Axter earned 200 total points
ID: 13808452
Better example:
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

int main(int argc, char* argv[])
{
   char buffer[20];
   char data[] = "Hello World";
   int i;
   for (i = 0;i < strlen(data);++i)
   {
       _itoa( data[i], buffer, 2 );
       printf( "%c = %s\n", data[i], buffer);
   }

    system("pause");
    return 0;
}

0
 
LVL 46

Assisted Solution

by:Kent Olsen
Kent Olsen earned 200 total points
ID: 13808618
Hi Hurb,

A character is stored in a data type called a 'char'.  A 'char' is really just an 8-bit integer.  Hence, a character IS stored in an integer and a string IS stored in an array of integers.  All you need do is display the string.

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

main()
{
   char *data = "Hello World";
   int i;

   for (i = 0; data [i]; i++)
     printf( " %c | %2x |  %3d\n", data[i], data[i], data[i]);
/*             char   hex      decimal  
                value  value    value    */
}

0
 
LVL 2

Author Comment

by:Hurb
ID: 13808706
Thanks very much.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Rules and regulations were devised in order to maintain the integrity of a system. However, interpretation of rules can be quite tricky.
Eseutil Hard Recovery is part of exchange tool and ensures Exchange mailbox data recovery when mailbox gets corrupt due to some problem on Exchange server.
Viewers will learn how to use the Hootsuite Dashboard.
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This videā€¦

571 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question