2 * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
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.
17 #include "NumberStream.h"
19 namespace smartcard_service_api
21 NumberStream::NumberStream(const ByteArray &T)
23 assign(T.getBuffer(), T.size());
26 unsigned int NumberStream::getBigEndianNumber() const
28 return getBigEndianNumber(*this);
31 unsigned int NumberStream::getLittleEndianNumber() const
33 return getLittleEndianNumber(*this);
36 NumberStream &NumberStream::operator =(const ByteArray &T)
40 assign(T.getBuffer(), T.size());
46 NumberStream &NumberStream::operator =(const NumberStream &T)
50 assign(T.getBuffer(), T.size());
56 unsigned int NumberStream::getBigEndianNumber(const ByteArray &T)
59 unsigned int result = 0;
61 len = (T.size() < 4) ? T.size() : 4;
63 for (i = 0; i < len; i++)
65 result = (result << 8) | T.at(i);
71 unsigned int NumberStream::getLittleEndianNumber(const ByteArray &T)
74 unsigned int result = 0;
76 len = (T.size() < 4) ? T.size() : 4;
78 for (i = 0; i < len; i++)
80 result = result | (T.at(i) << (i * 8));
86 } /* namespace smartcard_service_api */