Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

Going to binary to hex, and back (in C)

Name: Anonymous 2007-12-07 13:46

i want to write a little pseudo assembler in C. (please don't tell me how stupid of an idea this is) Is there a built-in function in C that allows me to go from ascii chars --> binary. And then go from binary --> hex. Something along the lines of how atoi() works? I couldn't find anything, it would save me some time though.

Name: Anonymous 2007-12-07 13:50

what

Name: Anonymous 2007-12-07 13:58

Use lisp and emacs.

Name: Anonymous 2007-12-07 13:59

Use haskell and vim.

Name: Anonymous 2007-12-07 14:04

Use python and gedit.

Name: Anonymous 2007-12-07 14:05

Use Java and Eclipse.

Name: Anonymous 2007-12-07 14:07

Use Web 2.0 and Textmate.

Name: Anonymous 2007-12-07 14:07

Use C++ and Anjuta.

Name: Anonymous 2007-12-07 14:07

ok...so i guess I will write my own function to go from ascii to binary

Name: Anonymous 2007-12-07 14:07

Use BASIC and Notepad.

Name: Anonymous 2007-12-07 14:08

>>9
No, you just do what >>3-8,10 said.

Name: Anonymous 2007-12-07 14:12

>>11
Or use BBCode and Shiichan.

Name: Anonymous 2007-12-07 14:14

Is there a Haskell equivalent of list-ref? Without the combinable cars and cudders accessing deeper elements of a list is a pain in the ass, so I need some simpler way of doing it (fst and snd don't combine like cars and cudders, ay?).

Name: Anonymous 2007-12-07 14:18

>>13
!!

Name: Anonymous 2007-12-07 14:18

>>13
My second fst is a snd.

Name: Anonymous 2007-12-07 14:19

Use Perl and Shell.

Name: Anonymous 2007-12-07 14:40

>>14
Need more info about its syntax.

Name: Anonymous 2007-12-07 14:43

>>17
oh wait

Name: Anonymous 2007-12-07 14:44

>>17
['a', 'b', 'c'] !! 1 => 'b'

You might be asking for something like setf though, which this isn't.

Name: Anonymous 2007-12-07 14:45

>>19
oh man thanks so awesome

Name: Anonymous 2007-12-07 14:45

ITT nobody cares about the OP

It's depressing ;_;

Name: Anonymous 2007-12-07 14:52

>>20
Also, use pattern matching when you can:

-- extracts the 4th element.
test (_:_:_:x:_) = x


Umm... I'm sure there's an advantage... I believe you get nicer error messages when it fails.  I suppose you can implement error checking easier too.

Name: Anonymous 2007-12-07 14:54

>>1
Is there a built-in function in C that allows me to go from ascii chars --> binary. And then go from binary --> hex.
Hahaha oh wow
Lern2C

In C (actually, in computers), anything is a number. What you store in a char is a series of bits. You then choose to represent (display) it as a number, a character, an hexadecimal number, etc.

For example:

char c = 65;
printf("As a character: %c", c);
printf("As an integer: %d", c);
printf("Hexadecimal number: %H", c);

Name: Anonymous 2007-12-07 14:56

>>21
he didn't clarify his question like >>2 wanted him too, it's his own fault

Name: Anonymous 2007-12-07 15:18


HAY GUYS I wrote a hex editor called shed that makes use of the following function I wrote. Its open sauce though, not pubic domain


 72 /* returns string representation of n in base 'base' */
   73 char *getstring(unsigned int n, char *s, int base, int width)
   74 {
   75   unsigned int i,j,c,d = calcwidth(n,base);
   76   char *p = s;
   77   if(width && d<width) {
   78     for(i=d;i<width;i++) {
   79       *p = '0';
   80       p++;
   81     }
   82   }
   83   for(i=d;i;i--) {
   84     j = pow(base,i-1);
   85     c = 0;
   86     while(n>=j) {
   87       n-=j;
   88       c++;
   89     }
   90     *p = c + ((c<10) ? 48 : 55);
   91     p++;
   92   }
   93   *p = 0;
   94   return s;


Removing the line numbers is left as an exercise for the reader

Name: Anonymous 2007-12-07 15:19

>>23
thank you sir, i was making this too difficult.

and btw the format identifier for hex is %X   ^_^

Name: Anonymous 2007-12-07 15:24

>>1
-->

Learn Haskell to learn proper type notation.

Name: Anonymous 2007-12-07 15:44

>>27
(->) is a function, not ``notation.''

Name: Anonymous 2007-12-07 15:45

>>25
s/\s+\d+\s+//

Name: Anonymous 2007-12-08 15:57

>>28
(->) is not a function.

Name: Anonymous 2009-03-18 2:25

Don't call me gay, but I need some mary jay!

Marijuana MUST be legalized.

Name: Anonymous 2011-01-31 20:38

<-- check em dubz

Don't change these.
Name: Email:
Entire Thread Thread List