Here you can find the source of booleanToBytes(boolean b)
Parameter | Description |
---|---|
b | The boolean to be converted. |
static public byte[] booleanToBytes(boolean b)
//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 w w. ja va 2 s.c o m * This function converts a boolean to its corresponding byte array format. * * @param b The boolean to be converted. * @return The corresponding byte array. */ static public byte[] booleanToBytes(boolean b) { byte[] buffer = new byte[1]; booleanToBytes(b, buffer); return buffer; } /** * This function converts a boolean into its corresponding byte format and inserts * it into the specified buffer. * * @param b The boolean to be converted. * @param buffer The byte array. * @return The number of bytes inserted. */ static public int booleanToBytes(boolean b, byte[] buffer) { return booleanToBytes(b, buffer, 0); } /** * This function converts a boolean into its corresponding byte format and inserts * it into the specified buffer at the specified index. * * @param b The boolean to be converted. * @param buffer The byte array. * @param index The index in the array to begin inserting bytes. * @return The number of bytes inserted. */ static public int booleanToBytes(boolean b, byte[] buffer, int index) { int length = 1; buffer[index] = (byte) (b ? 0xFF : 0x00); return length; } }