Here you can find the source of itob(int i, int j)
Parameter | Description |
---|---|
i | positive or 0 int to be converted. |
j | positive int length. |
public static byte[] itob(int i, int j)
//package com.java2s; /*//from w ww. ja v a 2 s . c om * Copyright (c) 2000 - 2005 Nokia Corporation and/or its subsidiary(-ies). * All rights reserved. * This component and the accompanying materials are made available * under the terms of "Eclipse Public License v1.0" * which accompanies this distribution, and is available * at the URL "http://www.eclipse.org/legal/epl-v10.html". * * Initial Contributors: * Nokia Corporation - initial contribution. * * Contributors: * * Description: * */ public class Main { /** * Creates a byte representation of the first argument * * @param i positive or 0 int to be converted. * @param j positive int length. * @return byte array. */ public static byte[] itob(int i, int j) { byte[] res = new byte[j]; for (int n = j - 1; n >= 0; n--) { res[n] = (byte) ('0' + (i % 10)); i = i / 10; } return res; } }