Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Empfohlene Antworten

Veröffentlicht

Hallo,

ich habe einen String eingelesen der eine Hexadezimale zahl enthält z.B. "3F2D"

ich möchte jetzt den Hex string in eine dezimale zahl umwandeln. z.B. "16173"

in diesem zusammenhang habe ich einmal eine funktion gefunden die mir eine zahl aus einem string macht (string = "1234" int ="1234")

int i_zahl = atoi(s_zahl);

solch eine funktion suche ich um einen Hex string in eine dezimale zahl umzuwandeln!

danke mfg

K & R:

long strtol(const char *s, char **endp, int base)

strtol converts the prefix of s to long, ignoring leading white

space; it stores a pointer to any unconverted suffix in *endp

unless endp is NULL. If base is between 2 and 36, conversion is

done assuming that the input is written in that base. If base is

zero, the base is 8, 10, or 16; leading 0 implies octal and leading

0x or 0X hexadecimal. Letters in either case represent digits from

10 to base-1; a leading 0x or 0X is permitted in base 16. If the

answer would overflow, LONG_MAX or LONG_MIN is returned, depending

on the sign of the result, and errno is set to ERANGE.

Auf Vorzeichenprüfung hab ich jetzt keinen Bock... und Überläufe lass ich laufen...



#include <ctype.h>


int Hex2Int(const char *hex)
{
int val = 0;

// skip leading"0x" or "0X"
if(hex[0] == '0' && (hex[1] == 'x' || hex[1] == 'X'))
hex += 2;

while(*hex)
{
int nibble;

if(*hex >= '0' && *hex <= '9')
nibble = *hex - '0';
else
nibble = 0xA + tolower(*hex) - 'a';
val = (val << 4) + nibble;
hex++;
}
return val;
}

[/PHP]

Sehr schön.

hat geholft :uli

Erstelle ein Konto oder melde dich an, um einen Kommentar zu schreiben.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.