---
name: "str_to_bytes"
section: "3"
platform: "linux"
package: "ltp-dev"
version: "20091231+dfsg-1"
release: "Debian 6.0 (Squeeze)"
platforms: ["linux"]
url: "https://new.carta.tech/str_to_bytes"
---

# str\_to\_bytes(3)

convert a string to a int byte count str\_to\_lbytes - convert a string to a long byte count str\_to\_llbytes - convert a string to a long long byte count

## NAME

str\_to\_bytes - convert a string to a int byte count str\_to\_lbytes - convert a string to a long byte count str\_to\_llbytes - convert a string to a long long byte count

## SYNOPSIS

int str\_to\_byte(char \**str*);\
 long str\_to\_lbyte(char \**str*);\
 long long str\_to\_llbyte(char \**str*);

## DESCRIPTION

**str\_to\_bytes()**, **str\_to\_lbytes()**, and **str\_to\_llbytes()** converts *str* to an integer, long, or long long  byte count.  *str* is an floating point number optionally followed by a single character multiplier. Currently the following multipliers are supported:

```
    Char  Meaning       Multiplier
    ----  ---------     --------------------------------
    b     Blocks        BSIZE or UBSIZE
    k     Kilobytes     2^10 (1024)
    K     Kilowords     2^10 (1024) * sizeof(long)
    m     Megabytes     2^20 (1048576)
    M     Megawords     2^20 (1048576) * sizeof(long)
    g     Gigabytes     2^30 (1073741824)
    G     Gigawords     2^30 (1073741824) * sizeof(long)
```

*str* is interpreted as floating point number (base 10). When using **str\_to\_llbytes()**, the uppercase suffix will result in multiplying by the size of a (long long) or 8.

## RETURNS

\-1 if the integer portion of *str* is invalid, if an unsupported multiplier is supplied, or if *str* has extra leading or trailing characters.  If *str* contains a negative number, the return value will be negative.

## EXAMPLES

**str\_to\_bytes("1000")**\

Returns 1000

**str\_to\_bytes("5b")**\

Returns 5 \* BSIZE.

**str\_to\_bytes("1.5m")**\

Returns 1.5 \* 1048576 or 1572864

## LIMITATIONS

**str\_to\_bytes()** and **str\_to\_lbytes()** when compiled as a 32 bit IRIX binary can only return a max number of 2g (2147483647). However, **str\_to\_lbytes()** is not limited by the 2g limit when compiled as 64 bit binary, where **str\_to\_bytes()** still is limited.

Note that the size of long will vary depending how if compiled as a 32 or 64 bit binary.  The size of a long long is always 8.

Also note that on a traditional CRAY system, a block is 4096 bytes, where on most IRIX systems a block is 1024 bytes.
