# perldoc > Bit::Vector::String

---
type: CommandReference
command: Bit::Vector::String
mode: perldoc
section: ""
source: perldoc
---

## Quick Reference

- `$vector->to_Oct()` — returns octal string
- `$vector->from_Oct($string)` — reads octal string into vector
- `Bit::Vector->new_Oct($bits,$string)` — constructor with octal string
- `$vector->String_Export($type)` — export in specified format
- `$vector->String_Import($string)` — import from string (auto-detect format)
- `Bit::Vector->new_String($bits,$string)` — constructor with auto-detected format

## Name

Generic string import/export for `Bit::Vector`

## Synopsis

perl
use Bit::Vector::String;

$string = $vector->to_Oct();
$vector->from_Oct($string);
$vector = Bit::Vector->new_Oct($bits,$string);
$string = $vector->String_Export($type);
$type = $vector->String_Import($string);
$vector = Bit::Vector->new_String($bits,$string);
($vector,$type) = Bit::Vector->new_String($bits,$string);
## Options

- `to_Oct()` — Returns an octal string (digits 0-7). No prefix. Least significant digit at right. About 40x slower than `to_Bin()`.
- `from_Oct($string)` — Reads octal string into vector. Accepts only digits 0-7; no prefix. If string too short, remaining bits cleared; if too long, extra ignored.
- `new_Oct($bits,$string)` — Constructor: creates new vector and calls `from_Oct()`. If `$bits` is `undef`, allocates 3*length($string) bits.
- `String_Export($type)` — Export vector in specified format. `$type` values:
  - `1` or `b` or `bin`: binary (`'0b'` prefix)
  - `2` or `o` or `oct`: octal (`'0o'` prefix)
  - `3` or `d` or `dec`: decimal (no prefix; sign is prefix)
  - `4` or `h` or `hex` or `x`: hexadecimal (`'0x'` prefix)
  - `5` or `e` or `enum`: enumeration (`'{'` and `'}'` delimiters)
  - `6` or `p` or `pack`: packed binary (`':' . size . ':'` prefix)
  - Default if `$type` omitted: hexadecimal.
- `String_Import($string)` — Import vector from a string. Automatically detects format (binary, octal, decimal, hex, enumeration, packed). Returns format number (1-6). Fatal error if unrecognized.
- `new_String($bits,$string)` — Constructor: creates new vector and calls `String_Import()`. If `$bits` is `undef`, calculates needed bits from input string. In list context, returns `($vector, $type)`.

## Examples

Export and import with prefixes:

perl
my $vector = Bit::Vector->new(8);
$vector->from_Bin('10101010');
my $hex = $vector->String_Export('hex'); # '0xaa'
my $bin = $vector->String_Export('bin'); # '0b10101010'
$vector->String_Import('0xff'); # sets to 11111111
Create from octal string:

perl
my $v = Bit::Vector->new_Oct(12, '377'); # 12 bits, value 0o377 = 255
print $v->to_Oct(); # prints '377'
## See Also

- [Bit::Vector(3)](https://www.chedong.com/phpMan.php/man/Vector/3/markdown)
- [Bit::Vector::Overload(3)](https://www.chedong.com/phpMan.php/man/Overload/3/markdown)