2 * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 #include "NumberStream.h"
20 namespace smartcard_service_api
22 NumberStream::NumberStream(const ByteArray &T)
24 setBuffer(T.getBuffer(), T.getLength());
27 unsigned int NumberStream::getBigEndianNumber()
29 return getBigEndianNumber(*this);
32 unsigned int NumberStream::getLittleEndianNumber()
34 return getLittleEndianNumber(*this);
37 NumberStream &NumberStream::operator =(const ByteArray &T)
41 setBuffer(T.getBuffer(), T.getLength());
47 NumberStream &NumberStream::operator =(const NumberStream &T)
51 setBuffer(T.getBuffer(), T.getLength());
57 unsigned int NumberStream::getBigEndianNumber(const ByteArray &T)
60 unsigned int result = 0;
62 len = (T.getLength() < 4) ? T.getLength() : 4;
64 for (i = 0; i < len; i++)
66 result = (result << 8) | T.getAt(i);
72 unsigned int NumberStream::getLittleEndianNumber(const ByteArray &T)
75 unsigned int result = 0;
77 len = (T.getLength() < 4) ? T.getLength() : 4;
79 for (i = 0; i < len; i++)
81 result = result | (T.getAt(i) << (i * 8));
87 } /* namespace smartcard_service_api */