Results 1 to 6 of 6

Thread: convert uint16_t

Hybrid View

  1. #1
    Join Date
    May 2013
    Beans
    27

    convert uint16_t

    hi all

    how can i convert uint16_t to char*?!
    i want to display value of uint16_t and i don't want to use printf or ... . i want to use system call function.

  2. #2
    Join Date
    Nov 2005
    Location
    Sendai, Japan
    Beans
    11,296
    Distro
    Kubuntu

    Re: convert uint16_t

    i want to use system call function.
    And just for kicks, which system call do you plan to use?
    「明後日の夕方には帰ってるからね。」


  3. #3
    Join Date
    May 2013
    Beans
    27

    Re: convert uint16_t

    i want to use "write()".

  4. #4
    Join Date
    Aug 2011
    Location
    47°9′S 126°43W
    Beans
    2,172
    Distro
    Ubuntu 16.04 Xenial Xerus

    Re: convert uint16_t

    Then convert the value to string using sprintf() or snprintf() and write() the result.

  5. #5
    Join Date
    Jun 2007
    Location
    Maryland, US
    Beans
    6,288
    Distro
    Kubuntu

    Re: convert uint16_t

    Quote Originally Posted by ferizhandi View Post
    hi all

    how can i convert uint16_t to char*?!
    i want to display value of uint16_t and i don't want to use printf or ... . i want to use system call function.
    There are two ways to write a number to a file using write(). You can convert the number to a string, and then write it (see ofnuts recommendation). Or you can write the value in binary. Which form do you require?

    P.S. Actually, if you require to write as text, then just use fprintf(). write() is really suitable for low-level output.

  6. #6
    Join Date
    Apr 2007
    Location
    (X,Y,Z) = (0,0,0)
    Beans
    3,715

    Re: convert uint16_t

    Unless you require to save this data as binary (in which case you have to use read/write), you're better using the higher level C standard I/O operations (fprintf et al.) so you get an automatic conversion from uint16_t to char * and viceversa. Be aware that this may be really useful if you plan to use output this value to stdout or if this value is to be retrieved from user input. Moreover, using ASCII files are much easier to debug than binary ones as only the former are human readable with a text editor.

    (Just my two cents)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •