0

I have been looking for the way that integers are converted to characters. I understand that there are ways using modulo and division to extract each number. I am looking for the way that programming languages do this.

Example:

int a = 101;
printf("%d\", &a);

This prints 101 to the console.

I want to understand how the bits 01100101 turn into "101" at the processor level.

belfner
  • 232
  • 1
  • 8
  • 1
    `printf` [seems to call _itoa](https://sourceware.org/git/?p=glibc.git;a=blob;f=stdio-common/vfprintf.c;h=fc370e8cbc4e9652a2ed377b1c6f2324f15b1bf9;hb=3321010338384ecdc6633a8b032bb0ed6aa9b19a), which [does the modulo and divide that you know](http://sourceware.org/git/?p=glibc.git;a=blob_plain;f=stdio-common/_itoa.h;hb=3321010338384ecdc6633a8b032bb0ed6aa9b19a) – aligur Sep 03 '19 at 20:46
  • 2
    If you search in your browser for "number base conversion", you'll find references that can explain this much better than we can manage here. – Prune Sep 03 '19 at 21:25
  • "looking for the way that programming languages" & "turn into "101" at the processor level" is two different question that involve different level of bit manipulation . | @aligur had answered your 1st question as for C language.. | but for the 2nd one.. you need to define/share how your device interpret printf().. then we can start somewhere.. | If you are using linux, run "man ascii" and you can see how the %c "A" is actually equivalent to %d "65", and both are having the same bit value. – p._phidot_ Sep 04 '19 at 05:32

1 Answers1

0

I want to understand how the bits 01100101 turn into "101" at the processor level.

It doesn't. At the Assembly level the meanings of bitpatterns are entirely dependent on their usage. If I do mov eax, 1 the computer doesn't know whether I mean the decimal number 1, the boolean true or even the ASCII delete character. Meaning is something humans ascribe to their programs.

I understand that there are ways using modulo and division to extract each number. I am looking for the way that programming languages do this.

This is pretty much what programming languages do, sometimes they will also use look up tables and such to speed things up but the core algorithm stays the same.

0x777C
  • 993
  • 7
  • 21