FMUSER Wirless Transmit Video And Audio More Easier !

[email protected] WhatsApp +8618078869184
Language

    C language common conversion tool functions

     

    1, character string turn hexadecimal Code: Void StrtoHEX (Char * PBDest, Char * PBSRC, INT NLEN) {Char H1, H2; CHAR S1, S2; INT I; For (i = 0; i {h1 = PBSRC [2 * i]; h2 = PBSRC [2 * i + 1]; S1 = TouPper (h1) - 0x30; // TouPper Convert to uppercase letters IF (S1 "9) S1 - = 7; S2 = TouPper (H2) - 0x30; IF (S2" 9) S2 - = 7; PBDEST [I] = S1 * 16 + S2;}} 2, hexadecimal string Code: Void Hextostr (Char * Pszdest, Char * PBSRC, INT NLEN) {Char DDL, DDH; for (INT I = 0; I "Nlen; i ++) {DDH = 48 + PBSRC [I] / 16; DDL = 48 + PBSRC [I]% 16; if (DDH "57) DDH = DDH + 7; IF (DDL" 57) DDL = DDL + 7; PSZDEST [i * 2] = DDH; PSZDEST [i * 2 + 1] = DDL; } pszdest [NLEN * 2] = ';} or U16 Hex2StringArray (U8 * PSRC, U16 Srclen, U8 * POBJ) {U16 I = 0; for (i = 0; I {Sprintf ((char *) (POBJ + I * 2), "% 02x", * (PSRC + i));} * (POBJ + I * 2) = ''; return (i * 2); Effect: Hexadecimal: 0x13 0xAA 0x02 to string: "13AAA2" 3, character string turn ten) Code: The first, if this is the negative, this is the implementation of the ATOI function: INT my_atoi (const char * str) {int value = 0; int flag = 1; // Judgment symbol while (* str == ') // Skip the space in front of the string {STR ++;} if (* str = = '-') // The first character is '-', the description may be negative {flag = 0; Str ++;} else if (* str == '+') // The first character is '+', The description may be positive {flag = 1; str ++;} // The first character is not '+' '-' nor a numeric character, return 0 else if (* str "= '9' || * STR" = '0') {return 0;} // When you encounter a non-digital character or '', end transformation while (* str! = '' && * str! = '9' && * Str "= '0' ) {Value = value * 10 + * STR - '0'; // convert the digital character to the corresponding shape Str ++;} IF (FLAG == 0) // negative case {value = -Value;} return value } Effect: String: "- 123" to -123 Second, if it is not negative: Void StrtODEC (uint32_t * pbdest, char * pbsrc, int NLEN) {INT i; int TMP = 0; if (NLEN "10) * pbdest = 0; TMP = 1; * pbdest = 0; for (i = Nlen-1 ; i "= 0; I -) {* PBDest + = TMP * (* (PBSRC + I) - '0'); TMP = TMP * 10;}} Effect: String: "123" to 123 The third type: contains turning to floating point: // m ^ n function // Return value: m ^ n times. U32 NMEA_POW (U8 M, U8 N) {u32 result = 1; while (n -) result * = m; return results;} // strn Result;} // Str Convert to numbers, end // BUF: Digital Save // ​​DX: Digital Switch // DX: Return Value: INT NMEA_STR2NUM (U8 * BUF, U8 *) DX) {u8 * p = buf; u32 IRES = 0, FRES = 0; U8 Ilen = 0, Flen = 0, I; U8 Mask = 0; int res; while (1) // Length of the integer and decimal length { IF (* p == '-') {mask | = 0x02; p ++;} // is negative number if (* p == ',' || (* p == * ')) Break; // encountered End the IF (* p == ') {mask | = 0x01; p ++;} // encountered a decimal point ELSE IF (* p "' 9 '|| (* p"' 0 ')) // Illegal characters {Ilen = 0; flen = 0; Break;} f (Mask & 0x01) Flen ++; Else Ilen ++; P ++;} if (mask & 0x02) buf ++; // remove negative for (i = 0; i {IRES + = NMEA_POW (10 , Ilen-1-i) * (BUF [I] - '0');} if (Flen "5) flen = 5; // Take up to 5 decimal * DX = flen; // Decimal point for (i = 0; I {FRES + = NMEA_POW (10, Flen-1-I) * (BUF [Ilen + 1 + I] - '0');} res = IRES * NMEA_POW (10, Flen) + Fres; IF (Mask & 0x02 RES = -res; return rs;} Effect: String: "123.456" first turn to 123456, then divide 1000 to get 123.456 4, decimal string Code: If it is just a single decimal string, you can use the sprintf function. If it is a decimal number: U16 DECTOSTR (U8 * PSRC, U16 Srclen, U8 * POBJ) {U16 I = 0; for (i = 0; I {Sprintf ((CHAR *) (POBJ + I * 2), "% 02D", * (PSRC + i));} * (POBJ + I * 2) = ''; return (i * 2); Effect: Decimal array 13 14 to string "1314" 5, U8, U32 conversion Lift a chestnut: ASCII code Write a picture description character 'a', one byte 8bit, U8 hexadecimal 0x41 binary 0100 0001 The corresponding decimal is 65 integer 65, 4 bytes 32bit, that is, the U32 hexadecimal is 0x41 binary 10000 0000 0001 Convert U32 to U8 arrays Note: Here is a character array, not a string The string is a Char array ended with empty characters () Void U32Tou8Array (uint8_t * buf, uint32_t u32value) {BUF [0] = ((U32Value "" 24) & 0xff); BUF [1] = ((U32Value "" 16) & 0xFF); buf [2] = U32Value "8) & 0xff); BUF [3] = (U32Value & 0xFF); Effect: Integer 50 turn character array {'', '', '', '2'} U8 array turn U32 Void u8ArrayTou32 (uint8_t * buf, uint32_t * u32value) {* u32Value = (buf [0] "" 24) + (BUF [1] "" 16) + (BUF [2] "" 8) + (BUF [3] "0); Effect: The character array {'', '', '', '2'} is turned to integer 50 6, large end small end Finally, the size is the problem. STM32 default is small-end mode, then how do you turn to a big end? 1, turn to the big end Big end: PPACK [0] = (U8) ((LEN "" 8) & 0xFF); PPACK [1] = (U8) (Len & 0xFF); Somarby: PPACK [0] = (U8) ( LEN & 0xFF); PPACK [1] = (U8) ((LEN "" 8) & 0xFF); Effect: LEN is a data type U16 (short), such as 0x11 0x22, and converts an array of U8 (USIGNED Char). The big end is: PPACK [0] (0x11) PPACK [1] (0x22) Small ends: PPACK [0] (0x22) PPACK [1] (0x11), Read more

     

     

     

     

    List all Question

    Nickname

    Email

    Questions

    Our other product:

    Professional FM Radio Station Equipment Package

     



     

    Hotel IPTV Solution

     


      Enter email  to get a surprise

      fmuser.org

      es.fmuser.org
      it.fmuser.org
      fr.fmuser.org
      de.fmuser.org
      af.fmuser.org ->Afrikaans
      sq.fmuser.org ->Albanian
      ar.fmuser.org ->Arabic
      hy.fmuser.org ->Armenian
      az.fmuser.org ->Azerbaijani
      eu.fmuser.org ->Basque
      be.fmuser.org ->Belarusian
      bg.fmuser.org ->Bulgarian
      ca.fmuser.org ->Catalan
      zh-CN.fmuser.org ->Chinese (Simplified)
      zh-TW.fmuser.org ->Chinese (Traditional)
      hr.fmuser.org ->Croatian
      cs.fmuser.org ->Czech
      da.fmuser.org ->Danish
      nl.fmuser.org ->Dutch
      et.fmuser.org ->Estonian
      tl.fmuser.org ->Filipino
      fi.fmuser.org ->Finnish
      fr.fmuser.org ->French
      gl.fmuser.org ->Galician
      ka.fmuser.org ->Georgian
      de.fmuser.org ->German
      el.fmuser.org ->Greek
      ht.fmuser.org ->Haitian Creole
      iw.fmuser.org ->Hebrew
      hi.fmuser.org ->Hindi
      hu.fmuser.org ->Hungarian
      is.fmuser.org ->Icelandic
      id.fmuser.org ->Indonesian
      ga.fmuser.org ->Irish
      it.fmuser.org ->Italian
      ja.fmuser.org ->Japanese
      ko.fmuser.org ->Korean
      lv.fmuser.org ->Latvian
      lt.fmuser.org ->Lithuanian
      mk.fmuser.org ->Macedonian
      ms.fmuser.org ->Malay
      mt.fmuser.org ->Maltese
      no.fmuser.org ->Norwegian
      fa.fmuser.org ->Persian
      pl.fmuser.org ->Polish
      pt.fmuser.org ->Portuguese
      ro.fmuser.org ->Romanian
      ru.fmuser.org ->Russian
      sr.fmuser.org ->Serbian
      sk.fmuser.org ->Slovak
      sl.fmuser.org ->Slovenian
      es.fmuser.org ->Spanish
      sw.fmuser.org ->Swahili
      sv.fmuser.org ->Swedish
      th.fmuser.org ->Thai
      tr.fmuser.org ->Turkish
      uk.fmuser.org ->Ukrainian
      ur.fmuser.org ->Urdu
      vi.fmuser.org ->Vietnamese
      cy.fmuser.org ->Welsh
      yi.fmuser.org ->Yiddish

       
  •  

    FMUSER Wirless Transmit Video And Audio More Easier !

  • Contact

    Address:
    No.305 Room HuiLan Building No.273 Huanpu Road Guangzhou China 510620

    E-mail:
    [email protected]

    Tel / WhatApps:
    +8618078869184

  • Categories

  • Newsletter

    FIRST OR FULL NAME

    E-mail

  • paypal solution  Western UnionBank OF China
    E-mail:[email protected]   WhatsApp:+8618078869184   Skype:sky198710021 Chat with me
    Copyright 2006-2020 Powered By www.fmuser.org

    Contact Us