BYTE manipulation functions

Source: Internet
Author: User
Tags types of functions

There are 2 groups of functions that manipulate multibyte fields

The name begins with a B (representing a byte)

The name begins with Mem (which represents memory).

They do not interpret the data or assume that the data is a C string that ends with a null character

When dealing with the socket address structure, my mom needed these types of functions because my mom needed to manipulate fields such as IP addresses, which could contain bytes of value bit 0, but not C strings.

The C string ending with a null character is handled by a function defined in the <string.h> header file, with the name beginning with Str.

void bzero (void *dest,size_t nbytes)

Bzero sets the specified number of bytes in the target string to 0, often using this function to initialize a socket address structure to 0

void bcopy (const void *src,void *dest,size_t nbytes)

Bcopy moves a specified number of bytes from the source byte string to the destination byte string

int bcmp (const void *ptr1,const void *ptr2,size_t nbyte)

BCMP compares 2 arbitrary strings, returns 0 if same, or not 0

void *memset (void *dest,int c,size_t len)

Memset The specified number of bytes in the target byte string to the value C

void *memcpy (void *dest,const void *src,size_t nbytes)

Memcopy is similar to bcopy, but the order of 2 pointer parameters is reversed

int memcmp (const void *ptr1,const void *ptr2,size_t nbytes)

MEMCMP compares 2 arbitrary byte strings, the same returns 0, if ptr1 refers to a byte string greater than PTR2 refers to the byte string, the return is greater than 0, otherwise less than 0

BYTE manipulation functions

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.