Java Byte Array to Boolean bytesToBoolean(byte[] buffer)

Here you can find the source of bytesToBoolean(byte[] buffer)

Description

This function converts the bytes in a byte array to its corresponding boolean value.

License

Open Source License

Parameter

Parameter Description
buffer The byte array containing the boolean.

Return

The corresponding boolean value.

Declaration

static public boolean bytesToBoolean(byte[] buffer) 

Method Source Code

//package com.java2s;
/************************************************************************
 * Copyright (c) Crater Dog Technologies(TM).  All Rights Reserved.     *
 ************************************************************************
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.        *
 *                                                                      *
 * This code is free software; you can redistribute it and/or modify it *
 * under the terms of The MIT License (MIT), as published by the Open   *
 * Source Initiative. (See http://opensource.org/licenses/MIT)          *
 ************************************************************************/

public class Main {
    /**//from w ww.j  a  v  a 2  s.c o  m
     * This function converts the bytes in a byte array to its corresponding boolean value.
     *
     * @param buffer The byte array containing the boolean.
     * @return The corresponding boolean value.
     */
    static public boolean bytesToBoolean(byte[] buffer) {
        return bytesToBoolean(buffer, 0);
    }

    /**
     * This function converts the bytes in a byte array at the specified index to its
     * corresponding boolean value.
     *
     * @param buffer The byte array containing the boolean.
     * @param index The index for the first byte in the byte array.
     * @return The corresponding boolean value.
     */
    static public boolean bytesToBoolean(byte[] buffer, int index) {
        return buffer[index] != 0;
    }
}

Related

  1. bytesToBooleanArray(byte[] input)
  2. bytesToBooleans(byte[] bytes)
  3. byteToBoolean(byte[] b)
  4. byteToBoolean(byte[] byt)